数据文件——之逐个字符串读取文本文件

代码:

 1 //This is c program code!
 2 /* *=+=+=+=+* *** *=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
 3   * 文档信息: *** :~/WORKM/stutyCode/cCode/recipesProblemSolution/chapter06/test6_5.c
 4   * 版权声明: *** :(魎魍魅魑)MIT
 5   * 联络信箱: *** :guochaoxxl@163.com
 6   * 创建时间: *** :2020年11月20日的下午09:49
 7   * 文档用途: *** :数据结构与算法分析-c语言描述
 8   * 作者信息: *** :guochaoxxl(http://cnblogs.com/guochaoxxl)
 9   * 修订时间: *** :2020年第46周 11月20日 星期五 下午09:49 (第325天)
10   * 文件描述: *** :自行添加
11  * *+=+=+=+=* *** *+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+*/
12 #include <stdio.h>
13 
14 int main(int argc, char **argv)
15 {
16     char *cPtr;
17     char store[80];
18     FILE *fPtr = fopen("kolkata.txt", "r");
19     if(fPtr != NULL){
20         puts("File kolkata.txt is opened successfully!");                               
21         puts("Contents of this file: ");
22         cPtr = fgets(store, 80, fPtr);
23 
24         while(cPtr != NULL){
25             printf("%s", store);
26             cPtr = fgets(store, 80, fPtr);
27         }
28 
29         int k = fclose(fPtr);
30         if(k == -1){
31             puts("File-closing failed!");
32         }
33         if(k == 0){
34             puts("\nFile is closed successfully.");
35         }
36     }else{
37         puts("File-opening failed!");
38     }
39 
40     return 0;
41 }

 

posted @ 2020-11-28 21:17  叕叒双又  阅读(142)  评论(0编辑  收藏  举报