我正在尝试从全局定义的文件file_in1中逐行向文本文件fileout写入内容。下面的代码出现了错误,我不知道原因。如果有人能找出问题所在,那就太好了。谢谢!
void output()
{
FILE *fileout;
char line[40];
file_in1 = fopen(filename1, "r");
printf("Please enter the name of the output file: ");
scanf("%s", filename); //Reads filename
fileout = fopen(filename, "w");
if (fileout == NULL) {
printf("(Ensure the file is located in the project \n file folder and has the .txt extension) \n");
output();
}
while (fgets(line, 90, file_in1) != NULL) //Looks through characters until end of the file
{
fputs(line, fileout);
}
}
fgets(line, 90, file_in1)
的吗?因为你声明了char line[40]
。 - Iharob Al Asimifile_in1
没有问题,当递归返回时,它将尝试在一个为NULL
的fileout
上进行写入。 - chrk