1. 程式人生 > >linux系統呼叫 建立檔案 file_creat.c

linux系統呼叫 建立檔案 file_creat.c

 void creat_file(char * filename)
{
    if(creat(filename,0755)<0)
     {
       printf("create file %s failure!\n",filename);
       exit(EXIT_FAILURE);
      }
    else
       printf("create file %s success!\n", filename);
}

int main(int argc, char *argc[ ])
{
     int i;
     if(argc<2)
       {
           perror("you have not input the filename, please try again!\n");
           exit(EXIT_FAILURE);
        }
    for (i=1;i<argc;i++)
        create_file(argv[i]);
     exit(EXIT_SUCCESS);
}

#gcc file_creat.c -o file_creat

#./file_creat  test1 test2

creat file test1 success!

creat file test2 success!