linux写入数据到文件,Linux下创建文件、并往文件中写入数据的小程序

#include

#include

#include

#include

#include

//创建文件

void create_file(char *filename)

{

if(creat(filename,0755)<0)

{

printf("create file %s failure!\n",filename);

exit(EXIT_FAILURE);

}

else

{

printf("create file %s sucess!\n",filename);

}

}

int main(int argc,char *argv[])

{

int i;

char buffer[]="hello world!";

char buffer1[1]; FILE *input;

if(argc<2)

{

perror("you haven't input the filename,please try again!\n");

exit(EXIT_FAILURE);

}

for(i=1;i

{

create_file(argv[i]);

//打开文件

input = fopen(argv[i],"wb");

if(input == NULL){

p

你可能感兴趣的:(linux写入数据到文件)