数据文件——之以批处理方式写入文本文件

  只想一股脑写如文本文件的可以参看,代码test6_3.c

 1 //This is c program code!
 2 /* *=+=+=+=+* *** *=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
 3   * 文档信息: *** :~/WORKM/stutyCode/cCode/recipesProblemSolution/chapter06/test6_3.c
 4   * 版权声明: *** :(魎魍魅魑)MIT
 5   * 联络信箱: *** :guochaoxxl@163.com
 6   * 创建时间: *** :2020年11月20日的下午07:26
 7   * 文档用途: *** :数据结构与算法分析-c语言描述
 8   * 作者信息: *** :guochaoxxl(http://cnblogs.com/guochaoxxl)
 9   * 修订时间: *** :2020年第46周 11月20日 星期五 下午07:26 (第325天)
10   * 文件描述: *** :自行添加
11  * *+=+=+=+=* *** *+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+*/
12 #include <stdio.h>
13 
14 int main(int argc, char **argv)
15 {
16     FILE *fPtr = fopen("kolkata.txt", "w");
17     if(fPtr != NULL){
18         puts("File kolkata.txt is opened successfully!");
19         fputs("Kolkata is very big city.\n", fPtr);
20         fputs("It is also very nice city.\n", fPtr);
21         int k = fclose(fPtr);
22         if(k == -1){
23             puts("File-close failed!");
24         }
25         if(0 == k){
26             puts("File-close successfully.");                                                                                                  
27         }
28     }else{
29         puts("File-opening failed!");
30     }
31 
32     return 0;
33 }

  运行的结果就是在当前目录下生成kolkata.txt的文本文件,内容为:

 1 Kolkata is very big city.                                                                                                                      
 2 It is also very nice city.~                             

 

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