Linux系统调用 – 资料操作

Linux系统调用 – 文件操作

系统调用方式创建文件  – 
测试程序一: test.c

#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){         //创建一个文件赋予755权限

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

                   exit(EXIT_FAILURE);

         }else{

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

         }

}

int main(int argc, char *argv[]){            //argc:参数的个数,argv数组:参数的名称数组,例如命令:hello 
liu,有两个参数,一个是hello命令,一个是liu,所以argc2

         int i;

         if(argc<2){                //
argc
小于2,即为没有参数跟在命令后面

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

                   exit(EXIT_FAILURE);

<span style="font-fa

Linux系统调用 – 资料操作

相关文章:

你感兴趣的文章:

标签云: