关于c中一个计数问题:怎样计算一个英文段落中的一,二,三等长度字母单词的出现个数
各位帮帮忙,是作业考试题呀!11!!!!加急的!!!!!!!!!
谁会?????给我发个信呀!!!!!!
#include <stdio.h> #include <stdio.h> #include <string.h> int main(int argc, char* argv[]) { FILE *fp; char buf[255]; int counts[3], i; counts[0] = counts[1] = counts[2] = 0; if(argc == 1) { printf("please specify data file.\n"); return 1; } fp = fopen(argv[1], "r"); if(!fp) { printf("open file \'%s\' failed.\n", argv[1]); return 1; } while(fscanf(fp, "%s", buf) != EOF) { while(buf[strlen(buf)-1] && !(('a'<=buf[strlen(buf)-1]&&buf[strlen(buf)-1]<='z') ||('A'<=buf[strlen(buf)-1]&&buf[strlen(buf)-1]<='Z'))) buf[strlen(buf)-1] = 0; if(0 < strlen(buf) && strlen(buf) < 4) ++counts[strlen(buf)-1]; } fclose(fp); for(i=0; i<3; ++i) printf("words with %d letters: %d\n", i+1, counts[i]); return 0; }