Problem statement
Write a program to calculate length of a string using user defined function.
Here don’t use standard string handling function strlen().
Program to print string length without using strlen()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include <stdio.h> #include<string.h> int main() { char str[50]; int i, len = 0; printf("Enter a string \n"); gets(str); for (i=0; str[i] != '\0'; i++) { len++; } printf("Length of string is %d", len); } |
Output
Enter a string
Webencyclop
Length of string is
11