C language realizes the complete code: input a line of characters, count the number of words in it, separate each word with spaces, and the number of spaces can be multiple...

#include<stdio.h> int main() { char str[200]; int count=0; printf("Please enter a line of characters: "); gets(str); for(int i=0;str[i] !='\0';i++) { if(str[i]==' ') count++; } printf("Number of words: %d\n",count+1); return 0; }

Guess you like

Origin blog.csdn.net/weixin_42601547/article/details/129573208