0
点赞
收藏
分享

微信扫一扫

creat( filename , 0111 )


#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 , 0111 ) <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);
}

[shikun@localhost FileProg]$ gcc file_creat.c -o  file_creat
[shikun@localhost FileProg]$ ./file_creat cteat2
create file cteat2 success!
[shikun@localhost FileProg]$ ls -l cteat2

0444
-r--r--r-- 1 shikun shikun 0 Sep 15 16:03 cteat2
[shikun@localhost FileProg]$ gcc file_creat.c -o  file_creat
[shikun@localhost FileProg]$ ./file_creat creat3
create file creat3 success!
[shikun@localhost FileProg]$ ls -l creat3

0111
---x--x--x 1 shikun shikun 0 Sep 15 16:05 creat3
[shikun@localhost FileProg]$


举报

相关推荐

0 条评论