zoukankan      html  css  js  c++  java
  • 在一个文件末尾增加字符串,并在控制台打印出来

     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 
     4 int main()
     5 {
     6     FILE *fp_write, *fp_read;
     7     char ch;
     8     char add[] = "An extra line
    ";
     9 
    10     fopen_s(&fp_write,"E:\first.txt","a+");
    11     if(fp_write == NULL)
    12     {
    13         printf("Can't open the file!
    ");
    14         system("pause");
    15         return 0;
    16     }
    17     //定位到文件末尾
    18     fseek(fp_write,0,SEEK_END);
    19     fputs(add,fp_write);
    20     //fwrite(add,sizeof(add),1,fp_write);
    21     //先关闭写入流再打开读出流
    22     fclose(fp_write);
    23 
    24     fopen_s(&fp_read,"E:\first.txt","r");
    25     if(fp_read == NULL)
    26     {
    27         printf("fp_read,Can't open the file!
    ");
    28         system("pause");
    29         return 0;
    30     }
    31     while((ch = fgetc(fp_read)) != EOF)
    32         putchar(ch);
    33 
    34     fclose(fp_read);
    35 
    36     system("pause");
    37     return 0;
    38 }
  • 相关阅读:
    转载-MongoDB 分片集群技术
    EXT4参数优化及测试---转载
    9.16周记
    PHP优化思路
    2018.09.10-拾遗
    周记8
    落地成盒-发快递
    周记7
    GTX log 6
    Gitlab Jenkins WebHook 持续集成配置踩坑记
  • 原文地址:https://www.cnblogs.com/cpsmile/p/4776877.html
Copyright © 2011-2022 走看看