Wednesday, July 20, 2011

Program to find length of a string including blank spaces,tabs, and other special characters

/*Serial No.100     [swami75.cpp]*/ 

/*New line character will be taken as a string terminating character.*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
int xstrlen(char *);
void main()
{
char s1[20];
int len;
clrscr();
printf("\nEnter the string:");
gets(s1);
len=xstrlen(s1);
printf("\nlength of the string =%d",len);
getch();
}
int xstrlen(char *s)
    {
    int l=0;
    while(*s)
      {
      l++;
      s++;
      }
    return (l);
    }

No comments:

Post a Comment

If you have any doubt, feel free to ask...