自学内容网 自学内容网

C语言的文件操作

目录

1、不带缓冲的I/O操作

1.1 creat函数(建立文件)

1.2 open函数(打开文件)

1.3 write函数(写入数据)

1.4 read函数(读取数据)

1.5 lseek函数(定位函数)

1.6 close函数(文件关闭函数)

1.7 综合案例:文件复制

 文件:cope_dome.c

2、带缓冲的I/O操作

2.1 3种缓冲类型

2.2 fopen函数

2.3 fclose函数

2.4 fdopen函数

2.5 fread函数

2.6 fwrite函数

2.7 fseek函数

2.8 ftell函数

2.9 fflush函数

2.10 setvbuf函数

3、 fgetc函数、getc函数、getchar函数

3.1 fgetc函数

3.2 getc函数

3.3 getchar函数

4、 fputc函数、putc函数、putchar函数

4.1 fputc函数

4.2 putc函数

4.3 putchar函数

5、 fgets函数与gets函数

5.1 fgets函数

5.2 gets函数

6、printf函数、fprintf函数、sprintf函数

6.1 printf函数

6.2 fprintf函数

6.3 sprintf函数

7、 scanf函数、fcanf函数、sscanf函数

7.1 scanf函数

7.1 fscanf函数

7.2 sscanf函数


文件描述符: 当某个程序打开文件时,操作系统返回相应的文件描述符,程序为了处理该文件必须引用此描述符。所谓的文件描述符,是一个低级的正整数。对于Linux而言,所有设备和文件操作都使用文件描述符来进行。文件描述符是一个非负的整数,它是一个索引值,并指向内核中每个进程打开文件的记录表。当打开一个现存文件或创建一个新文件时,内核向进程返回一个文件描述符,当要读写文件时,也需要把文件描述符作为参数传递给相应的函数

1、不带缓冲的I/O操作

creat、open、read、write、lseek、close

1.1 creat函数(建立文件)

函数详解

表头文件
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    
定义函数
    int creat(const char* pathname,mode_t mode);
    
函数说明
    用于建立文件
    参数pathname指向欲建立的文件路径的字符串
    mode表示若文件名不存在,则给创建的文件赋权限(0755,从第二个开始分别表示文件所有者、文件用户组、其他用户),1.执行 2.写入 4.读
​
返回值
    creat()会返回新的文件描述词

 综合案例

/*通过文件名建立文件,文件权限为0755,该文件名为creat_dome.c*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

//文件建立函数
void creat_file(char *filename)
{
if(creat(filename,0755) < 0)      //若<0表示建立失败
{
printf("create file %s failure!\n",filename);
exit(-1);
}
else
{
printf("create file %s success!\n",filename);
}
}

//主函数
int main(int argc,char *argv[])    //argc存的的是参数个数,argv存的是参数名称
{
int i;
if(argc < 2)       //先判断有几个参数
{
perror("you haven't input the filename,please try again!\n");
exit(-1);
}
for(i = 1;i < argc;i++)
{
creat_file(argv[i]);
}
return 0;
}

运行结果 

linux@ubuntu:~/test$ gcc creat_dome.c -o creat_dome -Wall
linux@ubuntu:~/test$ ./creat_dome a.c b.c c.c
create file a.c success!
create file b.c success!
create file c.c success!
1.2 open函数(打开文件)

函数详解

表头文件
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    
定义函数
    int open(const char* pathname,int flags);
    int open(const char* pathname,int flags,mode_t mode);
​
函数说明
    用于打开文件
    参数pathname指向欲建立的文件路径的字符串
    参数flags表示以何种方式打开文件
        O_RDONLY:以只读的方式打开文件
        O_WRONLY:以只写的方式打开文件
        O_RDWR:以读写的方式打开文件
    以上三种互斥,可与下列旗标利用OR(1)运算符进行组合。
    O_CREAT:若欲打开的文件不存在则自动创建该文件
    O_APPEND:以附加方式打开文件
    O_SYNC:以同步方式打开文件
    mode表示若文件名不存在,则给创建的文件赋权限(0755,从第二个开始分别表示文件所有者、文件用户组、其他用户),1.执行 2.写入 4.读
​
返回值
    若所有欲核查的权限都通过了检查返回0值,表示成功,只要有一个权限被禁止则返回-1,若正确打开文件返回新的文件描述词
1.3 read函数
表头文件
    #include <unistd.h>
    
定义函数
    ssize_t read(int fd,void* buf,size_t count);
    
函数说明
    从以打开的文件中读取数据
    fd 文件描述词
    buf 读取到的数据存储的地方
    count 读取的字节数
    
返回值
    返回值为实际读取到的字节数

 综合案例

/*打开文件,然后去关闭文件,文件不存在则创建文件,该代码文件名为open_dome.c*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

void open_file(char *filename);

int main(int argc,char *argv[])
{
int i = 1;

if(argc < 2)
{
perror("please input the open file pathname!\n");
exit(1);
}

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

return 0;
}

void open_file(char *filename)     //文件打开函数
{
int fd;

if((fd = open(filename,O_CREAT|O_RDWR,0755)) < 0)
{
perror("open file failure!\n");
exit(1);
}
else
{
printf("open file %s success!\n",filename);
}

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

return;
}

运行结果 

/*a.c b.c c.c都存在,只打开,的d.c不存在,为它新建了*/
linux@ubuntu:~/test$ gcc open_dome.c -o open_dome -Wall
linux@ubuntu:~/test$ ./open_dome a.c b.c c.c d.c
open file a.c success!
close file a.c success!
open file b.c success!
close file b.c success!
open file c.c success!
close file c.c success!
open file d.c success!
close file d.c success!
1.3 write函数(写入数据)

函数详解

表头文件
    #include <unistd.h>
    
定义函数
    ssize_t write(int fd,const void *buf,size_t count);
    
函数说明
    将数据写入已打开的文件内
    fd 文件描述词
    buf 待写入数据存储的地方
    count 写入的字节数
    
返回值
    返回值为实际写入的字节数

  综合案例

/*打开文件a.c b.c c.c往文件中写入abc*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

void write_file(char* filename);

int main(int argc,char *argv[])
{
int i;

if(argc < 2)
{
perror("please input the open file pathname!\n");
exit(1);
}

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

return 0;
}

void write_file(char* filename)
{
int fd;
char data[128];
sprintf(data,"this filename is %s",filename);
if((fd = open(filename,O_RDWR)) < 0)
{
printf("open file failure!\n");
return;
}

if(write(fd,data,strlen(data))<0)
{
perror("write file failure!\n");
}
else
{
printf("'%s' write success!\n",data);
}
close(fd);
return;
}

 运行结果 

linux@ubuntu:~/test$ gcc write_dome.c -o write_dome -Wall
linux@ubuntu:~/test$ ./write_dome a.c b.c c.c
'this filename is a.c' write success!
'this filename is b.c' write success!
'this filename is c.c' write success!
1.4 read函数(读取数据)

 函数详解

表头文件
    #include <unistd.h>
    
定义函数
    ssize_t read(int fd,void *buf,size_t count);
    
函数说明
    从已打开的文件中读取数据
    fd 文件描述词
    buf 读取到的数据存储的地方
    count 读取的字节数
    
返回值
    返回值为实际读取到的字节数

  综合案例

/*读取上边写入文件中的数据,并打印出*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

void read_file(char* filename);

int main(int argc,char *argv[])
{
int i = 0;

if(argc < 2)
{
perror("please input the open file pathname!\n");
exit(1);
}

for(i = 1;i < argc;i++)
{
read_file(argv[i]);
}
return 0;
}

void read_file(char* filename)
{
int fd = 0;
char buf[128] = {0};

if((fd = open(filename,O_RDONLY)) < 0)
{
perror("open file failure!\n");
return;
}
if(read(fd,buf,sizeof(buf)) < 0)
{
perror("read file failure!\n");
}
else
{
printf("%s的内容为:%s\n",filename,buf);
}

close(fd);
return;
}

 运行结果 

linux@ubuntu:~/test$ gcc read_file.c -o read_file -Wall
linux@ubuntu:~/test$ ./read_file a.c b.c c.c d.c
a.c的内容为:this filename is a.c
b.c的内容为:this filename is b.c
c.c的内容为:this filename is c.c
d.c的内容为:
1.5 lseek函数(定位函数)
表头文件
    #include <unistd.h>
    #include <sys/types.h>
    
定义函数
    off_t lseek(int fildes,off_t offset,int whence);
    
函数说明
    用于移动文件的读写位置
    fildes 文件描述词
    offset 偏移量,正数向后,负数向前
    whence
        SEEK_SET:参数offset为新的读写位置
        SEEK_CUR:以目前的读写位置往后增加offset个位移量
        SEEK_END:将读写位置指向文件尾后再增加offset个位移量
        
返回值
    当调用成功返回目前的读写位置,也就是距离开头多少个字节,错误返回-1
1.6 close函数(文件关闭函数)
表头文件
    #include <stdio.h>
    
定义函数 
    int close(int fd);
​
函数说明
    用于关闭open打开的文件
    
返回值
    成功返回0,错误返回EOF
1.7 综合案例:文件复制
 文件:cope_dome.c
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>

int main(int argc,char *argv[])
{
int from_fd,to_fd;
int read_bytes,write_bytes;
char *ptr;
char buf[1024] = {0};

if(argc != 3)
{
perror("please input true fromfile tofile!\n");
exit(1);
}

/*打开源文件*/
if((from_fd = open(argv[1],O_RDONLY)) < 0)
{
perror("open fromfile error!\n");
exit(1);
}

/*打开目标文件,若目标文件不存在则创建文件*/
if((to_fd = open(argv[2],O_CREAT|O_WRONLY,0755)) < 0)
{
perror("open tofile error!\n");
exit(1);
}

/*经典复制代码*/
while((read_bytes = read(from_fd,buf,sizeof(buf))))
{
/*当错误是信号中断的则直接跳出循环结束复制*/
if((read_bytes == -1)&&(errno!=EINTR)) break;
else if(read_bytes > 0)
{
ptr = buf;
while((write_bytes = write(to_fd,buf,read_bytes)))
{
if((write_bytes == -1)&&(errno!=EINTR)) break;
else if(write_bytes == read_bytes) break;       //写完所有读字节,结束循环
else if(write_bytes > 0)                        //若因为某种原因写中断了没能写完,则继续写
{
ptr+=write_bytes;                           //移动指针,将已经写入的数据去掉
read_bytes-=write_bytes;                    //减去以及写入的数据数量,剩下未写入的数据的数量
}
}
if(write_bytes == -1)break;                         //写的时候发生错误
}
}
close(from_fd);
close(to_fd);

exit(0);
return 0;                                                   //不会被执行到,留着为了程序完整性
}

运行结果 

linux@ubuntu:~/test$ gcc cope_dome.c -o cope_dome -Wall
linux@ubuntu:~/test$ ./cope_dome server.c a.c

//打开文件去看,它的内容全复制过去了
2、带缓冲的I/O操作
2.1 3种缓冲类型

全缓冲
    只有等填满标准I/O缓冲区后才进行实际I/O操作。通常标准I/O库实施全缓冲的。当再一个流上执行第一次I/O操作时,相关标准I/O函数通常调用malloc函数获得需使用的缓冲区
    “冲洗”用于说明I/O缓冲区的写操作。可有I/O历程自动冲洗,或者可以调用fflush函数冲洗一个流。

行缓冲
    当在输入输中遇到换行符时,在标准I/O库执行I/O操作
    设计终端设备的其他流,则它们是行缓冲

不带缓冲
    标准错误不带缓冲

2.2 fopen函数

  函数详解

表头文件
    #include <stdio.h>
​
定义函数
    FILE *fopen(const char* path,const char* mode);
    
函数说明
    用于打开文件
    path 包含欲打开文件路径和文件名
    mode 代表流的形态,有以下几种
        r:打开只读
        r+:读方式打开可读写
        w:写打开只写文件,文件存在则长度清0,文件不存在则建立文件
        w+:写打开可读写文件,文件存在则长度清0,文件不存在则建立文件
        a:以附加的方式打开只写文件
        a+:以附加的方式打开可读写文件
        以上字符串都可以再加一个b字符,表示打开的文件为二进制文件
        
返回值
    文件顺利打开,指向该流的文件指针被返回;打开失败,返回NULL

综合案例

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

int main(int argc,char *argv[])
{
FILE * a_fd;

if(argc != 2)
{
perror("please input filename!\n");
return 0;
}

if((a_fd = fopen(argv[1],"r")) == NULL)
{
printf("%s open failure!\n",argv[1]);
exit(-1);
}
printf("'%s' open success!\n",argv[1]);
fclose(a_fd);
return 0;
}

 运行结果 

linux@ubuntu:~/test$ gcc fopen_dome.c -o fopen_dome -Wall
linux@ubuntu:~/test$ ./fopen_dome a.c
'a.c' open success!
2.3 fclose函数

函数详解 

表头文件
    #include <stdio.h>
​
定义函数
    int fclose(FILE* stream);
​
函数说明
    用于关闭fopen打开的文件,会将缓冲区内的数据写入文件中,并释放系统所提供的文件资源
    stream 文件指针
​
返回值
    文件关闭成功则返回0,错误返回EOF
2.4 fdopen函数

函数详解 

表头文件
    #include <stdio.h>
​
定义函数
    FILE* fdopen(int fildes,const char* mode)
​
函数说明
    将文件描述词转为文件指针
    fildes 文件描述词
    mode 代表流的形态,有以下几种
        r:打开只读
        r+:读方式打开可读写
        w:写打开只写文件,文件存在则长度清0,文件不存在则建立文件
        w+:写打开可读写文件,文件存在则长度清0,文件不存在则建立文件
        a:以附加的方式打开只写文件
        a+:以附加的方式打开可读写文件
        以上字符串都可以再加一个b字符,表示打开的文件为二进制文件
​
返回值
    成功返回指向该流的文件指针,失败返回NULL

综合案例

#include <stdio.h>

int main(int argc,char *argv[])
{
FILE * fp = fdopen(0,"w+");       //0表示标准输入的文件描述符
fprintf(fp,"%s\n","hello!");      //格式化输出至文件,这里是格式化输出至标准输入
fclose(fp);
return 0;
}

运行结果  

linux@ubuntu:~/test$ gcc fdopen_dome.c -o fdopen_dome -Wall
linux@ubuntu:~/test$ ./fdopen_dome 
hello!
2.5 fread函数

函数详解  

表头文件
    #include <stdio.h>
​
定义函数
    size_t fread(void* ptr,size_t size,size_t nmemb,FILE* stream)
​
函数说明
    用于从文件中读取数据
    ptr 表示缓冲区地址
    size 表示待读取字节块大小(以字节为单位)
    nmemb 表示待读取字节块的个数
    stream 表示文件指针
​
返回值
    返回实际读取到的nmemb数目

 综合案例

#include <stdio.h>
#define nmemb 10

int main(int argc,char *argv[])
{
FILE *stream;
char s[nmemb];
stream = fopen("fread_dome.c","r");
fread(s,sizeof(char),nmemb,stream);

fclose(stream);
printf("%s\n",s);
return 0;
}

 运行结果  

linux@ubuntu:~/test$ gcc fread_dome.c -o fread_dome -Wall
linux@ubuntu:~/test$ ./fread_dome 
#include <
2.6 fwrite函数

函数详解   

表头文件
    #include <stdio.h>
​
定义函数
    size_t fwrite(const void* ptr,size_t size,size_t nmemb,FILE* stream)
​
函数说明
    用于将数据写入文件流
    ptr 表示缓冲区地址
    size 表示待写入字节块大小(以字节为单位)
    nmemb 表示待写入字节块的个数
    stream 表示文件指针
​
返回值
    返回实际写入的nmemb数目

 综合案例

#include <stdio.h>
#include <string.h>

#define set_s(x,y) {strcpy(s[x].name,y);s[x].size=strlen(y);}
#define nmemb 3

struct test
{
char name[20];
int size;
}s[nmemb];

int main(int argc,char *argv[])
{
FILE *fd;
if(argc != 2)
{
printf("please input open filename!\n");
return -1;
}

fd =fopen(argv[1],"w");
set_s(0,"Linux!\n");
set_s(1,"FreeBSD!\n");
set_s(2,"Windows2000\n");
fwrite(s,sizeof(struct test),nmemb,fd);
fclose(fd);
return 0;
}

运行结果  

linux@ubuntu:~/test$ gcc fwrite_dome.c -o fwrite_dome -Wall
linux@ubuntu:~/test$ ./fwrite_dome a.c
linux@ubuntu:~/test$ cat a.c
Linux!
FreeBSD!
Windows2000                     //写入的信息是整个结构体,故后边和还有写被翻译成特殊的字符的没有打印出来,正确的查看应该是将数据再读入结构体中,然后通过结构体内再进行获取数据

2.7 fseek函数

 函数详解   

表头文件
    #include <stdio.h>
​
定义函数
    int fseek(FILE* stream,long offset,int whence)
​
函数说明
    用于移动文件流的读写位置
    stream 已打开的文件指针
    offset 偏移量,正(前移)、负(后移)、0(保持不动)
    whence 偏移量的起始点
        SEEK_SET 文件开始处
        SEEK_CUR 当前位置
        SEEK_END 文件末尾
​
返回值
    成功返回0,错误返回-1

 综合案例 

#include <stdio.h>

int main(int argc,char *argv[])
{
FILE * stream;
char a[4];
a[3] = '\0';

stream = fopen("a.c","r");
fseek(stream,5,SEEK_SET);
fread(a,sizeof(char),3,stream);
printf("%s\n",a);
fclose(stream);

return 0;
}

运行结果 

linux@ubuntu:~/test$ gcc fseek_dome.c -o fseek_dome -Wall
linux@ubuntu:~/test$ cat a.c
abcdefghijklmn
linux@ubuntu:~/test$ ./fseek_dome
fgh
2.8 ftell函数

  函数详解   

表头文件
    #include <stdio.h>
    
定义函数
    long ftell(FILE* stream)
    
函数说明
    用于查看文件当前读写位置距文件开始处的字节数
    stream 文件指针
    
返回值
    当调用成功返回目前的读写位置,也就是距离开头多少个字节,错误返回-1

 综合案例

#include <stdio.h>

int main(int argc,char *argv[])
{
FILE * stream;
char a[4];
long int offset = 0;
a[3] = '\0';

stream = fopen("a.c","r");
fseek(stream,5,SEEK_SET);
fread(a,sizeof(char),3,stream);
printf("%s\n",a);
offset = ftell(stream);
printf("距离开头%ld个字节\n",offset);
fclose(stream);

return 0;
}

 运行结果 

linux@ubuntu:~/test$ gcc ftell_dome.c -o ftell_dome -Wall
linux@ubuntu:~/test$ ./ftell_dome 
fgh
距离开头8个字节
2.9 fflush函数
表头文件
    #include <stdio.h>
    
定义函数
    int fflush(FILE *fp)
    
函数说明
    刷新缓冲区,将输出缓冲区中所有未写入数据发送到fp指定的输出文件
    fp 文件指针
​
返回值
2.10 setvbuf函数
表头文件
    #include <stdio.h>
    
定义函数
    int setvbuf(FILE * restrict fp,char * restrict buf,int mode,size_t size)
    
函数说明
    创建一个供标准I/O函数替换使用的缓冲区。打开文件后未对流进行其他操作之前。调用该函数
    fp 识别待处理的流
    buf 指向待使用的存储区
    mode 表示缓冲类型
        _IOFBF 完全缓冲(缓冲区满时刷新)
        _IOLBF 行缓冲(缓冲区满时或写入一个换行符时)
        _IONBF 无缓冲
        
返回值
    操作成功返回0,否则返回一个非0的值
3、 fgetc函数、getc函数、getchar函数
3.1 fgetc函数
表头文件
    #include <stdio.h>
    
定义函数
    int fgetc(FILE * fp)
    
函数说明
    用于从文件中读取一个字符
    fp 字符指针
    
返回值
    返回读取到的字符,若读到文件尾而无数据返回EOF
3.2 getc函数
表头文件
    #include <stdio.h>
    
定义函数
    int getc(FILE * fp)
    
函数说明
    同fgetc从文件中读取一个字符,但它为宏定义
    
返回值
    返回读取到的字符,若读到文件尾而无数据返回EOF
3.3 getchar函数
表头文件
    #include <stdio.h>
    
定义函数
    int getchar(void)
    
函数说明
    从标准输入设备中读取一个字符,将字符从char转换成int并返回
    它也是宏定义,是getc(stdin)的宏定义
    
返回值
    返回值读取到字符,若返回EOF则表示有错误发生
4、 fputc函数、putc函数、putchar函数
4.1 fputc函数
表头文件
    #include <stdio.h>
    
定义函数
    int fputc(int c,FILE * stream)
    
函数说明
    将参数c转换成char后写入stream指定的文件中
    
返回值
    返回写入成功的字符。若返回EOF表示写入错误
4.2 putc函数
表头文件
    #include <stdio.h>
    
定义函数
    int putc(int c,FILE* stream)
    
函数说明
    同fputc函数,但putc为宏定义
    
返回值
    返回写入成功的字符。若返回EOF表示写入错误
4.3 putchar函数
表头文件
    #include <stdio.h>
    
定义函数
    int putchar(int c)
    
函数说明
    将字符c写入标准输出设备
    它也是宏定义,是putc(c,stdout)的宏定义
    
返回值
    返回写入成功的字符。若返回EOF表示写入错误
5、 fgets函数与gets函数
5.1 fgets函数
表头文件
    #include <stdio.h>
    
定义函数
    char * fgets(char * s,int size,FILE* stream)
    
函数说明
    用于从stream所指的文件内读入字符并存入s所指的空间中,直到出现换行符、文件结尾或者size-1个字符为止,最后会加上NULL结束
    从文件中读取以字符串
    
返回值
    若读取成功则返回s指针;返回NULL则表示有错误发生
5.2 gets函数
表头文件
    #include <stdio.h>
    
定义函数
    char* gets(char *s)
    
函数说明
    用于从标准设备中读入字符并存到参数s所指的内存空间中,直到出现换行符、文件结尾或者size-1个字符为止,最后会加上NULL结束
    从标准输入设备中读取以字符串
    
返回值
    若读取成功返回s指针;返回NULL则表示有错误发生
6、printf函数、fprintf函数、sprintf函数
6.1 printf函数
表头文件
    #include <stdio.h>
    
定义函数
    int printf(const char * format,...)
    
函数说明
    格式化输出数据
    
返回值
    返回实际输出的字符数,失败返回-1
6.2 fprintf函数
表头文件
    #include <stdio.h>
    
定义函数
    int fprintf(FILE* stream,const char * format,...)
    
函数说明
    格式化输出数据至文件
    
返回值
    返回实际输出的字符数,失败返回-1
6.3 sprintf函数
表头文件
    #include <stdio.h>
    
定义函数
    int sprintf(char *str,const char * format,...)
    
函数说明
    用于格式化字符串复制
    根据参数format字符串来转换并格式化数据,再将结果复制到参数str所指定的字符串数组中直到出现(\0)为止
    
返回值
    返回str字符串长度,失败返回-1
7、 scanf函数、fcanf函数、sscanf函数
7.1 scanf函数
表头文件
    #include <stdio.h>
    
定义函数
    int scanf(const char * format,...)
    
函数说明
    用于格式化字符输入
    
返回值
    成功返回参数数目,失败返回-1
7.1 fscanf函数
表头文件
    #include <stdio.h>
    
定义函数
    int fscanf(FILE* stream,const char *format,...)
    
函数说明
    从文件指针stream中读取字符串,再根据参数format字符串来转换并格式化数据
    
返回值
    成功返回参数数目,失败返回0
7.2 sscanf函数
表头文件
    #include <stdio.h>
    
定义函数
    int sscanf(const char *str,const char *format,...)
    
函数说明
    将参数str的字符串根据参数format字符串来转换并格式化数据
    
返回值
    成功返回参数数目,失败返回-1


原文地址:https://blog.csdn.net/qq_55869380/article/details/142454784

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!