关键C函数备录

一.搜索指定路径下的文件

(1) intptr_t _findfirst(const char *, struct _finddata_t *);//可以使用通配符*或?

(2) int _findnext(intptr_t, struct _finddata_t *);//使用搜索句柄,继续搜索

(3) int _findclose(intptr_t);//关闭搜索句柄,并释放相关资源

示例:

 1 #include <stdio.h> 
 2 #include <io.h>  
 3 int main(void) 
 4 {  
 5     intptr_t handle;  
 6     struct _finddata_t fileInfo = {0};//存储文件信息的结构体变量   
 7     if(-1 != (handle = _findfirst(".//*.log", &fileInfo)))
 8     {   
 9         printf("文件名:%s
", fileInfo.name);   
10         while(-1 != _findnext(handle, &fileInfo))//循环输出所有文件名   
11         {    
12             printf("文件名:%s
", fileInfo.name);   
13         }   
14         _findclose(handle);//释放句柄  
15     }  
16     return 0; 
17 }    

 二.文件的读写操作

(1) int fgetc(FILE *stream);

功能:从文件中读取一个字符,并将stream指向下移一个位置。

返回:如果调用成功,返回字符。当到达文件结尾或有错误发生时,返回EOF。

解析:文件把EOF作为结束标志。

(2) char* fgets(char* str, int num,FILE *stream);

原文地址:https://www.cnblogs.com/shijianchuzhenzhi/p/4314796.html