file_creat

#include <stdio.h> 
#include <stdlib.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

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 success!\n",filename);
}
}

int main(int argc,char *argv[]){
int i;
if(argc<2){
perror("you haven't input the filename,please try again!\n");
exit(EXIT_FAILURE);
}

for(i=1;i<argc;i++){
create_file(argv[i]);
}

exit(EXIT_SUCCESS);
}

编译后运行 ./file_creat a 便能创建文件a

posted on 2011-11-30 09:36  小风儿_xf  阅读(262)  评论(0编辑  收藏  举报

导航