这个简单的程序,在 fgets() 中给我带来麻烦,返回 EOF,这是 fgets() 的错误值 不明白问题出在哪里
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
FILE* openFile(const char* path)
{
FILE* file;
file = fopen(path, "r");
if(file == NULL)
{
perror(path);
exit(EXIT_FAILURE);
}
return file;
}
int main()
{
FILE* file;
char stringVector[6] = "hello";
file = openFile("/home/user/workspace/fputs/src/testo.txt");
if(fputs(&stringVector[0], file) == EOF)
{
printf("error in fputs");
fclose(file);
exit(EXIT_FAILURE);
}
fclose(file);
return 0;
}
最佳答案
您正在打开文件进行读取,但仍试图向其中写入数据?这没有意义。
关于c - 简单的 fputs() 示例返回 EOF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14755121/