- 論壇徽章:
- 0
|
Redhat linux環(huán)境下的C語言程序,普通用戶登陸,沒有開發(fā)板,用vi來編寫程序并調(diào)試、運(yùn)行。
把書上的程序完全輸進(jìn)去之后,再編譯。
顯示如下的錯(cuò)誤信息:
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);
}
注:那個(gè)“fcnt1.h”的“1”,是阿拉伯?dāng)?shù)字,而不是小寫的“L”。
請(qǐng)問:到底哪里出了問題?該怎么改?請(qǐng)?jiān)敿?xì)解答。
謝謝。 |
|