#include <stdio.h>
#include <string.h>
int main()
{
int i;
int counter=0, counter2=0;
char *s;
char name[30];
char vowel[6] = "AEIOU";
char consonants[21] = "BCDFGHJKLMNPQRSTVWXYZ";
printf ("input the string: ");
scanf ("%s", name);
printf ("The string is %s\n", name);
for (i=0; name[i]!='\0'; i++) {
if (s = strchr(vowel, name[i])) {
counter++;
}
else if (s =strchr(consonants, name[i])) {
counter2++;
}
printf ("First counter is %d\n", counter);
printf ("The second counter is %d\n", counter2);
return 0;
}
}
問題是,我的代碼有什麼問題?爲什麼櫃檯不工作? 因爲我嘗試了很多方法,沒有任何工作,也許有人可以爲我解釋。我想找到在我的字符串中有多少元音和輔音C
您可能會添加程序失敗的方式 - 是否打印任何內容?它打印什麼? – nietaki 2012-03-25 23:20:53
這與您之前的問題有何不同? http://stackoverflow.com/questions/9864558/stack-with-finding-character-inside-string-in-c-language – 2012-03-25 23:21:27
請在將來,縮進你的代碼。它可以幫助你,它可以幫助閱讀你的代碼的人(包括你的老師)。 – 2012-03-25 23:22:43