数据文件——之读取文本文件中的整数
代码:
1 //This is c program code! 2 /* *=+=+=+=+* *** *=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= 3 * 文档信息: *** :~/WORKM/stutyCode/cCode/recipesProblemSolution/chapter06/test6_9.c 4 * 版权声明: *** :(魎魍魅魑)MIT 5 * 联络信箱: *** :guochaoxxl@163.com 6 * 创建时间: *** :2020年11月21日的上午10:28 7 * 文档用途: *** :数据结构与算法分析-c语言描述 8 * 作者信息: *** :guochaoxxl(http://cnblogs.com/guochaoxxl) 9 * 修订时间: *** :2020年第46周 11月21日 星期六 上午10:28 (第326天) 10 * 文件描述: *** :自行添加 11 * *+=+=+=+=* *** *+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+*/ 12 #include <stdio.h> 13 14 void closeState(int clo, FILE *fPtr){ 15 clo = fclose(fPtr); 16 if(clo == -1){ 17 puts("File-closing failed."); 18 } 19 if(clo == 0){ 20 puts("File is closed successfully."); 21 } 22 23 return; 24 } 25 int main(int argc, char **argv) 26 { 27 FILE *fPtr = fopen("numbers.dat", "r"); 28 int col; 29 if(fPtr != NULL){ 30 puts("File numbers.dat is opened successfully."); 31 puts("Contents of file numbers.dat: "); 32 int n; 33 int num = fscanf(fPtr, "%d\t", &n); 34 35 while(num != EOF){ 36 printf("%d\t", n); 37 num = fscanf(fPtr, "%d\t", &n); 38 } 39 printf("\n"); 40 closeState(col, fPtr); 41 }else{ 42 puts("File-opening failed!"); 43 } 44 45 return 0; 46 }
人就像是被蒙着眼推磨的驴子,生活就像一条鞭子;当鞭子抽到你背上时,你就只能一直往前走,虽然连你也不知道要走到什么时候为止,便一直这么坚持着。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具