下面的代码无法编译。在我的 Visual Studio 中的 STDOUT_FILENO 下有一条弯线,它没有提供任何关于如何更正它的建议。
#include <stdio.h>
#include <stdlib.h>
#include "read_file.h"
void main()
{
char ch, file_name[25];
//FILE *fp;
FILE *fd;
int num_read;
printf("Enter the name of file you wish to see\n");
gets(file_name);
fd = fopen(file_name, "O_RDONLY");
if (fd < 0)
{
perror("Error while opening the file.\n");
exit(EXIT_FAILURE);
}
printf("The contents of %s file are :\n", file_name);
for (;;)
{
num_read = fread(fd, ch, sizeof(ch));
if (num_read < '0')
{
perror("Error while reading the file.\n");
exit(EXIT_FAILURE);
}
if (num_read == 0)
{
break;
}
fwrite(STDOUT_FILENO, ch, sizeof(ch));
}
}