📝⚡Beginner
Find the Length of a String
Find length without strlen
Find string length manually by counting characters until the null terminator (\\0).
Program Code
string_length.c
C
1#include <stdio.h>23int stringLength(char str[]) {4 int length = 0;5 while (str[length] != '\0') {6 length++;7 }8 return length;9}1011int main() {12 char str[100];13 14 printf("Enter a string: ");15 scanf("%99s", str);16 17 printf("Length of \"%s\" = %d\n", str, stringLength(str));18 return 0;19}Output
Enter a string: Hello
Length of "Hello" = 5
Related Examples
Want to Learn More?
Explore our comprehensive tutorials for in-depth explanations of C programming concepts.
Browse Tutorials