C program to find length of a string using while Loop and pointer.












C program to find length of a string using while Loop and pointer.




C program to find length of a string using while Loop and pointer.



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


Output:
Enter any string: c programming Length of enter string 'c programming' = 13




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