C program to find length of a string using for Loop.












C program to find length of a string using for Loop.




C program to find length of a string using for Loop.



#include <stdio.h> #define MAX 200 int main() { char text[MAX]; int i; int count= 0; printf("\n Enter any string: "); gets(text); for(i=0; text[i]!='\0'; i++) { count++; } printf("\n Length of enter string '%s' = %d", text, count); return 0; }


Output:
Enter any string: computer Length of enter string 'computer' = 8



Exercise: 1
Write a C program to find length of a string.