-4
,我想我的程序執行以下操作:777 1)創造一個名爲FILENAME.TXT 2文件)分配權限)收件「這將是輸出到TESTFILE.TXT \ n「到新創建的文件C編程創建並寫入文件
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#define PERMS 0777
int main(int argc, char *argv[])
{
int createDescriptor;
int openDescriptor;
char fileName[15]="Filename.txt";
if ((openDescriptor = open(fileName, O_CREAT | O_WRONLY)) == -1)
{
printf("Error creating %s\n", fileName);
exit(EXIT_FAILURE);
}
umask(0000);
if ((openDescriptor = creat(fileName, PERMS)) == -1)
{
printf("Error creating %s", fileName);
exit(EXIT_FAILURE);
}
if(write(openDescriptor,"This will be output to testfile.txt\n",36) != 36)
{
write(2,"There was an error writing to testfile.txt\n",43);
return 1;
}
if((close(openDescriptor))==-1)
{
write(2, "Error closing file.\n", 19);
}
return 0;
}
這是什麼問題? – sqreept
爲什麼我寫的這個程序不工作?就是那個問題。 – John