Implement a C program to count total number of words in a string. The given input words can be of letters, digits and special character. For example, if "I love India" is given as input, the output should be the total number of words is 3".
#include<stdio.h>
#include<string.h>
void main(){
char s[200];
int count=0;
printf("enter your string \n");
scanf("%[^\n]s",s);
for(int i=0;s[i]!='\0';i++){
if(s[i]==' ' && s[i+1]!=' ')
count++;
}
printf("Number of word in given string is %d",count+1);
}
Comments
Leave a comment