/*
成都網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)公司!專注于網(wǎng)頁設(shè)計、重慶網(wǎng)站建設(shè)公司、微信開發(fā)、小程序開發(fā)、集團成都企業(yè)網(wǎng)站定制等服務(wù)項目。核心團隊均擁有互聯(lián)網(wǎng)行業(yè)多年經(jīng)驗,服務(wù)眾多知名企業(yè)客戶;涵蓋的客戶類型包括:成都三輪攪拌車等眾多領(lǐng)域,積累了大量豐富的經(jīng)驗,同時也獲得了客戶的一致表揚!
#define FLAGS O_RDWR|O_APPEND
#define SIZE 80
#define FILENAME "/home/mrhe/hello"
int main(int argc, char argv[])
{
int count;
int fd;
char write_buf[SIZE];
const char pathname=FILENAME;
if((fd=open(pathname,FLAGS))==-1)//調(diào)用open函數(shù)打開文件
{
printf("error,open file failed!\n");
exit(1);
}
printf("OK,open file successful!\n");
printf("Begin write:\n");
gets(write_buf);
count=strlen(write_buf);
if(write(fd,write_buf,count)==-1)//要寫入文件的數(shù)據(jù)的字節(jié)數(shù)
{
printf("error,write file failed!\n");
exit(1);
}
printf("OK,write %d strings to file!\n",count);
return 0;
}