|
我用C写了一个程序,可就是不能向文件“test.dat”中写入字符。代码如下:
[php]
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#define NEWFILE (O_WRONLY|O_CREAT|O_TRUNC)
int main(void)
{
int outfile,n;
char filename[ ]={"test.dat"};
char file[]={"hello,how are you"};
if(outfile=open(filename, NEWFILE, 0640)==-1)
{
printf("ERROR, OPEN FILE FAILED! \n");
exit(255);
}
if(n=write(outfile,file,sizeof(file))==-1)
{printf("writed file error\n");
exit(255);
}
close(outfile);
return 0;
}
[/php]
:help |
|