fork download
  1. #include<stdio.h>
  2. int calculatelength(char*);
  3.  
  4. void main()
  5. {
  6. char str1[25];
  7. int l;
  8. printf("\n\n Pointer: Calculate the length of the string: \n");
  9. printf("------------------------------------------------- \n");
  10.  
  11. printf("Input a string: ");
  12. fgets(str1, sizeof str1, stdin);
  13.  
  14. l= calculatelength(str1);
  15. printf("The length of the given string %s is : %d", str1, l-1);
  16. printf("\n\n");
  17.  
  18. }
  19.  
  20. int calculatelength(char* ch) //ch=base address of array str1 (&str1[0])
  21. {
  22. int ctr = 0;
  23. while (*ch != '\0')
  24. {
  25. ctr++;
  26. ch++;
  27. }
  28. return ctr;
  29. }
Success #stdin #stdout 0.01s 5516KB
stdin
45
stdout

 Pointer: Calculate the length of the string: 
------------------------------------------------- 
Input a string: The length of the given string 45 is : 1