Find String Length in C++

  1. #include < stdio.h > main()  
  2. {  
  3.     int mystrlen(char * );  
  4.     char s[100];  
  5.     char * p = s;  
  6.     printf("Enter the string\n");  
  7.     while (( * p = getchar()) != '\n') ++p; * p = '\0';  
  8.     p = s;  
  9.     int x = mystrlen(p);  
  10.     printf("length of string=%d\n", x);  
  11. }  
  12. int mystrlen(char * p)  
  13. {  
  14.     int c = 0;  
  15.     while ( * p != '\0')  
  16.     {  
  17.         c++; * p++;  
  18.     }  
  19.     return (c);  
  20. }