【发布时间】:2013-05-19 13:08:51
【问题描述】:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
char data [ 6 ];
main ( ) {
int len;
desc = open ( "Resultat", O_WRONLY | O_CREAT | O_EXCL, 0666 );
if ( desc != -1 ) {
len = write ( desc, &data, sizeof ( data ) );
if ( len != sizeof ( data ) )
printf ( "ERROR" );
} }
这是我的代码,我收到了错误
O_WRONLY undeclared (first use in this function)
O_CREAT undeclared (first use in this function)
O_EXCL undeclared (first use in this function)
我该如何解决这个问题?
【问题讨论】:
-
你在哪个平台上?一旦我将
int数据类型分配给desc,这将为我在 CentOS 5 和 CentOS 6 上构建 -
#include
? -
ubuntu 9.10,我添加了#include
但仍然是同样的错误.. -
我的机器 (mac) 显示在
sys/fcntl.h中定义的O_WRONLY,请尝试包含它。 -
一个名为
test的程序的问题在于shell 也有一个名为test(又名[)的内置函数。除非您运行./test(即使.在$PATH上),否则它会优先于您的程序调用。