zoukankan      html  css  js  c++  java
  • 数据文件——之逐个字符写入文本文件

    代码:

     1 //This is c program code!
     2 /* *=+=+=+=+* *** *=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
     3   * 文档信息: *** :~/WORKM/stutyCode/cCode/recipesProblemSolution/chapter06/test6_6.c
     4   * 版权声明: *** :(魎魍魅魑)MIT
     5   * 联络信箱: *** :guochaoxxl@163.com
     6   * 创建时间: *** :2020年11月20日的下午10:22
     7   * 文档用途: *** :数据结构与算法分析-c语言描述
     8   * 作者信息: *** :guochaoxxl(http://cnblogs.com/guochaoxxl)
     9   * 修订时间: *** :2020年第46周 11月20日 星期五 下午10:22 (第325天)
    10   * 文件描述: *** :自行添加
    11  * *+=+=+=+=* *** *+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+*/
    12 #include <stdio.h>
    13 
    14 int main(int argc, char **argv)
    15 {
    16     FILE *fPtr = fopen("jaipur.txt", "w");
    17     if(fPtr != NULL){
    18         puts("File jaipur.txt is opened successfully.");
    19         puts("Enter text to be written to file. Enter * to");
    20         puts("terminate the text-entry-session.");
    21         
    22         int ch = getchar(); 
    23         while(ch != '*'){
    24             fputc(ch, fPtr);
    25             ch = getchar();                                                             
    26         }   
    27         
    28         int clo = fclose(fPtr);
    29         if(clo == -1){
    30             puts("File-cloing failed");
    31         }   
    32         if(clo == 0){
    33             puts("File is close successfully.");
    34         }   
    35     }else{
    36         puts("File-opening failed!");
    37     }   
    38     
    39     return 0;
    40 }
  • 相关阅读:
    C++ map的基本操作和用法
    堆排序汇总
    gdb调试多进程和多线程命令
    Linux内存分配机制
    svn 修改文件的可执行权限
    proc/sys/net/ipv4/下各项的意义
    linux read()和write
    ps命令参数
    /etc/passwd- 和/etc/shadow-文件
    openssh源码分析笔记
  • 原文地址:https://www.cnblogs.com/guochaoxxl/p/14054149.html
Copyright © 2011-2022 走看看