• 在一个文件末尾增加字符串,并在控制台打印出来


     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 }
  • 相关阅读:
    leetcode-409
    leetcode-836
    leetcode-1160
    leetcode-面试题13
    leetcode-695
    go的一些小lib
    leetcode-300
    cookie
    php上传文件
    PHP 文件创建/写入
  • 原文地址:https://www.cnblogs.com/cpsmile/p/4776877.html
Copyright © 2020-2023  润新知