Q:

C Program to Calculate the length of the string using a pointer

0

C Program to Calculate the length of the string using a pointer

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
int calculateLength(char*);
 
void main() 
{
   char str1[25];
   int l;
	printf("\n\n Pointer : Calculate the length of the string :\n"); 
	printf("---------------------------------------------------\n");
   
   printf(" Input a string : ");
   fgets(str1, sizeof str1, stdin);
   
   l = calculateLength(str1);
   printf(" The length of the given string %s is : %d ", str1, l-1);
   printf("\n\n");

}
 
int calculateLength(char* ch) 
{
   int ctr = 0;
   while (*ch != '\0') 
   {
      ctr++;
      ch++;
   }
   return ctr;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now