C program to find the length of a string without using library function
belongs to collection: C programs - StringsC programs - Strings
All Answers
total answers (1)
belongs to collection: C programs - StringsC programs - Strings
total answers (1)
C program to find the length of a string without using library function - Source code
Program Output
Program Explanation
1. The program accepted the string from the user using the gets function and stored it in character array. The maximum size of array is declared as 500. Strings in C are treated as character arrays.
2. An integer variable length is declared and initialize to 0.
3. Starting with first index of array[0], the whole string is traversed until it encounters NULL.
4. Variable length is increased by one with every loop iteration and printed at last.
5. Here note that if you enter a sentence instead of string, the white spaces will also be counted as the length of the string.
need an explanation for this answer? contact us directly to get an explanation for this answer