我正在制作一个程序,它将congress.txt
中的字符全部大写,然后“将它们转换为两个字符”,(A转到C)(Z转到B)。但是没有任何内容正在打印,我主要关心的是如果我的数组正在被存储并传递给不同的功能。为什么没有打印? C编程
这是在congress.txt
:
国会不得制定法律尊重建立宗教或禁止自由行的;或者删除言论自由或新闻自由;或和平集会的人民的权利,并请求政府纠正不满。
#include<stdio.h>
int processFile(int *store);
int cipher(int *store, int *code);
int outputCode(int *code);
int main(void){
int store[300], code[300], i;
processFile(store);
cipher(store, code);
outputCode(code);
getchar();
return 0;
}
void processFile(int *store){
int i, a = 0;
FILE *f = fopen("congress.txt", "r");
for (i = 0; a != EOF;){
fscanf(f, "%c", &a); //store character in a
if (a <= 'Z' && a >= 'A'){ //store uppercase letters
store[i] = a;
i++;
}
if (a <= 'z' && a >= 'a'){ //store lowercase letters as uppercase
store[i] = a - 32;
i++;
}
}
i++;
store[i] = '\0';
}
void cipher(int *store, int *code){
int i;
for (i = 0; store[i] != 0; ++i){
if (store[i] <= 'X' && store[i] >= 'A'){ //tests to see if the letter is between A and X
code[i] = (char)(store[i] + 2); //shifts letter by two characters
}
if (store[i] >= 'Y' && store[i] <= 'Z'){
code[i] = (char)(store[i] - 24); //shifts Y and Z to A or B respectively
}
}
}
void outputCode(int *code){
int i, a, b;
for (a = 0; code[a] != 0; ++a){
if (!(a % 50)){ //makes a newline every 50 characters
printf("\n");
}
for (b = 0; code[a] != 0 && b <= 5; ++b){ //prints chunks of 5 characters then makes a space
printf("%c", code[a]);
}
printf(" ");
}
}
你应该明确提出终止''\ 0''你在'processFile'字符串的结尾... – Floris
你或许应该改变你的'回报; '返回0;'或者因为函数必须返回一个'int'。另外,你的其他函数也应该返回一个值。如果你不需要,将返回类型改为'void'。我建议编译您的代码,并启用所有警告以尽早检测这些微小的错误。 – Rufflewind
弗洛里斯会编辑我即将做到这一点? – ShaneBird