我花了好几个小时试图弄清楚如何从输入文件中读取字符串、处理它并在 3 个不同的输出文件中写入元音、辅音和数字。这是我达到的代码:
void discriminator(input, output1, output2, output3) {
if (string[i] == 'a' || string[i] == 'e' || string[i] == 'i' || string[i] == 'o' || string[i] == 'u' || ) {
fputs(string[i], output1);
i = i + sizeof(string[i]);
}
else if (int string[i]) {
fputs(string[i], output2);
i = i + sizeof(string[i]);
}
else {
fputs(string[i], output3);
i = i + sizeof(string[i]);
}
}
int main() {
FILE *inFile = fopen("input.txt","r");
FILE *outVocali = fopen("outputVocali.txt", "w");
FILE *outNumeri = fopen("outputNumeri.txt", "w");
FILE *outConsonanti = fopen("outputConsonanti.txt", "w");
char *string;
char *fgets(string, EOF, inFile);
int i = 0;
while(fgets(string, EOF, inFile)) {
discriminator(inFile, outVocali, outNumeri, outConsonanti);
}
fclose(inFile);
fclose(outVocali);
fclose(outNumeri);
fclose(outConsonanti);
return 0;
}
这是编译器写的:
esercizio.c:6:9: 错误:使用未声明的标识符 'string' if (string[i] == 'a' || string[i] == 'e' || string[i] == 'i' || 串... ^
esercizio.c:6:16: 错误:使用未声明的标识符 'i' if (string[i] == 'a' || string[i] == 'e' || string[i] == 'i' || 串... ^
esercizio.c:6:29:错误:使用未声明的标识符 'string' if (string[i] == 'a' || string[i] == 'e' || string[i] == 'i' || 串... ^
esercizio.c:6:36: 错误:使用未声明的标识符 'i' if (string[i] == 'a' || string[i] == 'e' || string[i] == 'i' || 串... ^
esercizio.c:6:49: 错误:使用未声明的标识符 'string' if (string[i] == 'a' || string[i] == 'e' || string[i] == 'i' || 串... ^
esercizio.c:6:56: 错误: 使用未声明的标识符 'i' if (string[i] == 'a' || string[i] == 'e' || string[i] == 'i' || 串... ^
esercizio.c:6:69:错误:使用未声明的标识符“字符串”...==“a”|| 字符串[i] == 'e' || 字符串[i] == 'i' || 字符串[i] == 'o' || 圣... ^
esercizio.c:6:76: 错误:使用未声明的标识符 'i' ...'a' || 字符串[i] == 'e' || 字符串[i] == 'i' || 字符串[i] == 'o' || 串... ^
esercizio.c:6:89:错误:使用未声明的标识符“字符串”...==“e”|| 字符串[i] == 'i' || 字符串[i] == 'o' || 字符串[i] == '你' || ) { ^
esercizio.c:6:96: 错误:使用未声明的标识符 'i' ...'e' || 字符串[i] == 'i' || 字符串[i] == 'o' || 字符串[i] == '你' || ) { ^
esercizio.c:6:109: 错误:预期表达式 ...'e' || 字符串[i] == 'i' || 字符串[i] == 'o' || 字符串[i] == '你' || ) { ^
esercizio.c:7:15:错误:使用未声明的标识符“字符串”fputs(字符串 [i],输出 1);^
esercizio.c:7:22: 错误:使用未声明的标识符 'i' fputs(string[i], output1); ^
esercizio.c:8:9: 错误:使用未声明的标识符 'i' i = i + sizeof(string[i]); ^
esercizio.c:8:13: 错误:使用未声明的标识符 'i' i = i + sizeof(string[i]); ^
esercizio.c:8:24: 错误: 使用未声明的标识符'string' i = i + sizeof(string[i]); ^
esercizio.c:8:31: 错误:使用未声明的标识符 'i' i = i + sizeof(string[i]); ^
esercizio.c:10:14: 错误:预期表达式 else if (int string[i]) { ^
esercizio.c:11:15:错误:使用未声明的标识符“字符串”fputs(字符串 [i],输出 2);^
致命错误:发出太多错误,现在停止 [-ferror-limit=] 生成 20 个错误。
有没有人有任何指示?