Wednesday, November 26, 2008

C Programming Solved - Session 9

27. Function to return the length of a character string:

#include
#include
int calc(char *x)
{
int count =0;
while(*x != '\0')
{
count++;
x++;
}
return(count);
}
void main()
{
clrscr();
char *i;
char ch[30];
printf("\nPlease enter text without space:");
scanf(" %s",ch);
i=&ch[0];
printf("\n\nLenght of given String:%d",calc(i));
getch();
}

No comments: