- 论坛徽章:
- 0
|
Redhat linux环境下的C语言程序,普通用户登陆,没有开发板,用vi来编写程序并调试、运行。
把书上的程序完全输进去之后,再编译。
显示如下的错误信息:
open.c:5:18: fcnt1.h:No such file or directory
open.c: In function 'main':
open.c:11: error: 'O_CREAT' undeclared(first use in this function)
open.c:11: error: (Each undeclared identifier is reported only once
open.c:11: error: for each function it appears in.)
open.c:11: error: 'O_TRUNC' undeclared(first use in this function)
open.c:11: error: 'O_WRONLY' undeclared(first use in this function)
完整的源代码如下(是书上的):
/*open.c*/
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcnt1.h>
#include<stdlib.h>
#include<stdio.h>
int main(void)
{
int fd;
if((fd=open("/tmp/hello.c",O_CREAT|OTRUNC|O_WRONLY,0600))<0)
{
perror("open:");
exit(1);
}
else
{
printf("Open file:hello.c %d\n",fd);
}
if(close(fd)<0)
{
perror("close:");
exit(1);
}
else
printf("Close hello.c\n");
exit(0);
}
注:那个“fcnt1.h”的“1”,是阿拉伯数字,而不是小写的“L”。
请问:到底哪里出了问题?该怎么改?请详细解答。
谢谢。 |
|