[问题]Ubuntu里写C语言程序出错。

软件和网站开发以及相关技术探讨
回复
林杰杰
帖子: 193
注册时间: 2005-07-03 15:30
来自: 广州

[问题]Ubuntu里写C语言程序出错。

#1

帖子 林杰杰 » 2005-08-19 20:20

小弟在写程序的时候,出现了一个错误,源程序如下:
#include <fcnt1.h>
#include <sys/stat.h>
#include <sys/types.h>

#define NEWFILE (O_WRONLY | O_CREAT | O_TRUNC)
#define MODE600 (S_IRUSR | S_IWUSR)
#define SIZE 1

void fatal(char* s)
{
printf("error when %s\n",s);
exit(-1);
}

void filecopy(char* infile,char* outfile)
{
char buf[SIZE];
int infd,outfd,count;

infd = open(infile,O_RDONLY);
if (infd == -1)
{
fatal("opening infile.\n");
}

outfd = open(infile,NEWFILE,MODE600);
if (outfd == -1)
{
close(infd);
fatal("opening outfile.\n");
}

while ((count = read(infd,buf,sizeof(buf))) > 0)
{
if (write(outfd,buf,count) != count)
{
fatal("writing data.\n");
}
}

if (count == -1)
{
fatal("reading data.\n");
}
close(infd);
close(outfd);
}

int main(int argc,char* argv[])
{
if (argc < 3)
{
printf("usage:filecopy <s-file> <d-file>");
return 1;
}
filecopy(argv[1],argv[2]);
return 0;
}

编译时出现这样的错:
lin@LIN:~/C++$ cc 2.c
2.c:1:19: fcnt1.h: No such file or directory
2.c: In function `filecopy':
2.c:20: error: `O_RDONLY' undeclared (first use in this function)
2.c:20: error: (Each undeclared identifier is reported only once
2.c:20: error: for each function it appears in.)
2.c:26: error: `O_WRONLY' undeclared (first use in this function)
2.c:26: error: `O_CREAT' undeclared (first use in this function)
2.c:26: error: `O_TRUNC' undeclared (first use in this function)
这是为什么呢?我是照着书打的。
  再把Xwindow叫成X windows的,一律不予理睬。
  三个以上感叹号连打或有事没事都打感叹号的,也不予理睬。
头像
yonsan
帖子: 887
注册时间: 2005-07-01 18:56
来自: 广州市

#2

帖子 yonsan » 2005-08-19 20:29

#include <fcnt1.h>

将你的fcnt1.h改为fcntl.h就可以了! 那个是字母L的小写l而不是数字1
I will be back!
林杰杰
帖子: 193
注册时间: 2005-07-03 15:30
来自: 广州

#3

帖子 林杰杰 » 2005-08-19 21:29

yonsan 写了:#include <fcnt1.h>

将你的fcnt1.h改为fcntl.h就可以了! 那个是字母L的小写l而不是数字1
Faint...
谢谢这位兄弟了。
  再把Xwindow叫成X windows的,一律不予理睬。
  三个以上感叹号连打或有事没事都打感叹号的,也不予理睬。
回复