我创建了一个创建文本文件的程序,要求用户输入任何数据,然后保存它,然后将相同的内容复制到另一个文件中,但是在大写字母中。但每当我在Netbeans中启动它时,它就会在几毫秒内停止而不做任何事情。这是我的完整代码:
int main() {
FILE *f;
FILE *g;
char c, d;
f = fopen("/Users/Mansoor/Desktop/GRIMM2.txt", "r");
if (!f) {
printf("File Couldn't be Opened.");
} else {
printf("File opened successfully.\n");
printf("Write Anything: ");
while ( c != EOF ) {
c = getchar();
putc(c, f);
}
printf("Wrote Successful.\n");
fclose(f);
}
f = fopen("/Users/Mansoor/Desktop/GRIMM2.txt", "r");
g = fopen("/Users/Mansoor/Desktop/GRIMM4.txt", "w");
while ((c = fgetc(f)) != EOF) {
d = toupper(c);
putc(d, g);
}
printf("Converted to Upper Case and copying in new file... Successful!");
fclose(f);
fclose(g);
}
答案 0 :(得分:0)
先改变" r"到" r +"或" w"我想当你第一次创建这个程序时,你已经拥有了那个" GRIMM2.txt"文件就是为什么它有效。