小弟在写程序的时候,出现了一个错误,源程序如下:
#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)
这是为什么呢?我是照着书打的。
[问题]Ubuntu里写C语言程序出错。
-
- 帖子: 193
- 注册时间: 2005-07-03 15:30
- 来自: 广州
[问题]Ubuntu里写C语言程序出错。
再把Xwindow叫成X windows的,一律不予理睬。
三个以上感叹号连打或有事没事都打感叹号的,也不予理睬。
三个以上感叹号连打或有事没事都打感叹号的,也不予理睬。
- yonsan
- 帖子: 887
- 注册时间: 2005-07-01 18:56
- 来自: 广州市