write the function to find of the string which is passed from main program using pointers
Runtime Input :
hello
Output :
5
#include <stdio.h>
int lengthOfString(char* string)
{
int length = 0;
while(*string!='\0')
{
length++;
string++;
}
return length;
}
int main()
{
char* hello = "hello";
printf("Input: %s\n",hello);
int length = lengthOfString(hello);
printf("Output: %d", length);
printf("\n\n");
return 0;
}
Comments
Leave a comment