Finding no. of characters, spaces and tabs in C:
#include<stdio.h>
int main()
{
char str[50];
int i=0,characters=0,space=0,tab=0;
puts("enter the string");
gets(str);
for(i=0;i<strlen(str);i++)
{
if(str[i]=='\t') tab++;
else if(str[i]==' ') space++;
else characters++;
}
printf("characters=%d\ttab=%d\tspace=%d",characters,tab,space);
getch();
return 0;
}
OUTPUT:
enter the string
hai hello how are you
characters=17 tab=2 space=2
#include<stdio.h>
int main()
{
char str[50];
int i=0,characters=0,space=0,tab=0;
puts("enter the string");
gets(str);
for(i=0;i<strlen(str);i++)
{
if(str[i]=='\t') tab++;
else if(str[i]==' ') space++;
else characters++;
}
printf("characters=%d\ttab=%d\tspace=%d",characters,tab,space);
getch();
return 0;
}
OUTPUT:
enter the string
hai hello how are you
characters=17 tab=2 space=2
No comments:
Post a Comment