Wednesday, 23 April 2014

27. Write a function that will return the length of a character string. You are not allowed to use the strlen C library function. Note: Use "Pointers" concept



/* function to find string length */
# include<stdio.h>
# include<conio.h> main()
{
char str1[50]; char * c;
int len;
int lenstring(char *); clrscr();
printf("enter a string :"); scanf("%s",str1);
c = str1; len=lenstring(c);
printf("Length of the string is : %d\n",len); getch();
}
int lenstring(char *c1)
{
int count=0; while(*c1!=\0)
{ c1++;
count ++;
}
return count;
}

No comments:

Post a Comment