萌新求帮助,c语言:文件中的单词统计和替换
单词和个数都要列出来,好难啊,
求大佬救命c⌒っ゚Д゚)っ
#include <stdio.h> #include<ctype.h> #define M 1000 #define N 20 void beep(); void GetPassage(char str[]); void WordSepa(char str[], char word[][M]); int main() { char str[M]; int strC[N]; char word[M/N][M]; GetPassage(str); printf("%s\n",str); WordSepa(str, word); } void beep() { printf("\07"); } void GetPassage(char str[]) { char ch; int i=0; while(1) { ch=getchar(); if(ch=='\n') break; else if(i<M) str[i++]=ch; else beep(); } str[i]='\0'; } void WordSepa(char str[], char word[][M]) { int i=0, j = 0, k=0; int flag = 1; while(flag) { for(; !isalpha(str[j]); j++) ; while(isalpha(str[j])) word[i][k++] = str[j++]; word[i][k] = '\0'; printf("单词 %d : %s\n", i + 1, word[i]); k = 0; ++i; if(str[j] == '\0') flag = 0; } }