輸入字符串,實現(xiàn)單詞的分離并計數(shù)用函數(shù)不知道為什么編譯出來什么word【i】根本沒有沒有語法錯誤。strC是計數(shù),記錄每個word【i】出現(xiàn)地次數(shù)str是保存字符串word【】【】是一個單詞一個word【i】求幫忙看一下,自己debug了一整天都不行,初學(xué)C語言,拜托指點一下。#include <stdio.h>#include <string.h>#include<conio.h>#include<ctype.h>#define M 1000#define N 20void beep();void GetPassage(char str[]);void WordSepa(char str[],int strC[],char word[][20]);void main(){?char str[M];?int strC[N];?char word[M/N][N];?GetPassage(str);?printf("%s\n",str);?WordSepa(str,strC,word);}void beep(){?printf("\07");}void GetPassage(char str[]){?char ch;?int i=0;?while(1){?ch=getch();?if(ch=='\r')??break;???? if(ch=='\b'){??if(i>0){??printf("%c %c",ch,ch);???i--;??}??else???beep();??continue;?}?if(ch!=32&&ch!=44&&ch!=46&&isalpha(ch)==0){??beep();??continue;}?if(i<N){?printf("%c",ch);? str[i++]=ch;?}?else?? beep();??}?str[i]='\0';}void WordSepa(char str[],int strC[],char word[][20]){int i=0,j=0,k=0,t=0,x=0;while(j<t) {for(;str[j]==32;j++);while(k<N&&str[j]!=32) word[i][k++]=str[j++];word[i][k]='\0';strC[i]=1;for(x=0;x<i;x++) if(stricmp(word[i],word[x])==0){strC[x]++;i--; break; }i++; k=0;}t=0; for(;t<i;t++)printf("%s(%d)\n",word[t],strC[t]);}
不知道哪里邏輯錯誤
qq_nanranlanW_0
2017-05-14 16:24:28