//输入一行字符,用函数编程统计其中有多少个单词。假设单词之间用空格分开。 //要求:请在指定范围内补充语句(不能修改、增加、删除输入、输出语句), //使程序运行能够完成指定的功能。 #include <stdio.h> int CountWords(char mystr[]); #define N 80

int main() { char str[N]; int count; fgets(str, sizeof(str), stdin); //修改范围--开始 count = CountWords(str); //修改范围--结束 printf("%d", count); return 0; } int CountWords(char mystr[]) { int i, num; num = (mystr[0] != ' ') ? 1 : 0; for (i = 1; mystr[i] != '\0'; i++) { //修改范围--开始 if (mystr[i] == ' ' && mystr[i-1] != ' ') { num++; } //修改范围--结束 } return num;

输入一行字符用函数编程统计其中有多少个单词。假设单词之间用空格分开。要求:请在指定范围内补充语句不能修改、增加、删除输入、输出语句使程序运行能够完成指定的功能。#include stdiohint CountWordschar mystr;#define N 80int main	char strN;	int count;	fgetsstr sizeofstr stdin;	修改范围--开始	;

原文地址: http://www.cveoy.top/t/topic/hriS 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录