Write a program to read a sentence and counts the total number of character (excluding space) using while loop.

#include<stdio.h>
#include<string.h>
int main()
{
int count=0,i=0;
char word[50];
printf("enter the string:");
scanf("%[^\n]",word);
while(word[i]!='\0')
{
if(word[i]==' ' && word[i+1]!=' ')
{
count++;
}
i++;
}
printf("the total number of character is %d",strlen(word)-count);
}

Comments

Popular posts from this blog