2011年11月30日

file_open

摘要: #include<stdio.h>#include<stdlib.h>#include<sys/types.h>#include<sys/stat.h>#include<fcntl.h>int main(int argc, char *argv[]){ int fd; if(argc < 2) { puts("please input the filename!\n"); exit(1); } if((fd = open(argv[],O_CREAT|O_RDWR,0755)) < 0) ... 阅读全文

posted @ 2011-11-30 22:12 小风儿_xf 阅读(199) 评论(0) 推荐(0) 编辑

main(int argc,char *argv[ ])

摘要: main(int argc,char *argv[ ])argv为指针的指针argc为整数char **argv or: char *argv[] or: char argv[][]main()括号内是固定的写法。下面给出一个例子来理解这两个参数的用法:假设程序的名称为prog,当只输入prog,则由操作系统传来的参数为:argc=1,表示只有一程序名称。argc只有一个元素,argv[0]指向输入的程序路径及名称:./prog当输入prog para_1,有一个参数,则由操作系统传来的参数为:argc=2,表示除了程序名外还有一个参数。argv[0]指向输入的程序路径及名称。argv[1]指 阅读全文

posted @ 2011-11-30 12:43 小风儿_xf 阅读(186) 评论(0) 推荐(0) 编辑

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{ pr 阅读全文

posted @ 2011-11-30 09:36 小风儿_xf 阅读(262) 评论(0) 推荐(0) 编辑

导航