zoukankan      html  css  js  c++  java
  • 数据文件——之以批处理方式写入文本文件

      只想一股脑写如文本文件的可以参看,代码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.
    ", fPtr);
    20         fputs("It is also very nice city.
    ", 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.~                             
  • 相关阅读:
    perimeter of squares
    map
    django路由
    for的骚用法
    3和5的倍数相加和
    PeteCake 字典和最小值
    Find the missing letter
    实现简单的ssh功能
    开源运维工具体系
    vsftp在iptables中的配置
  • 原文地址:https://www.cnblogs.com/guochaoxxl/p/14012042.html
Copyright © 2011-2022 走看看