A program to find the length of given string using pointer and function.
A program to find the length of given string using pointer and function.
Codes
/*A program to find the length of given string using pointer and function*/
/*Programed by Jitendra Kr Yadav
10116
2Apr,2011*/
#include<stdio.h>
#include<conio.h>
main()
{
char string[20];
int count=0;
char *ptr;
printf("Enter the string: ");
gets(string);
for(ptr=&string[0];*ptr!='\0';ptr++)
if(*ptr!=' ')
count+=1;
else
continue;
printf("Number of characters = %d.\n\n",count);
printf("Press any key to continue...");
getch();getch();
}
Output
Enter the string: Hello there
Number of character = 10.
Press any key to continue…









Comments (1)