Answer to Question #198276 in C for Prasanna

Question #198276

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".


1
Expert's answer
2021-05-25T04:35:41-0400
#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);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS