zoukankan      html  css  js  c++  java
  • 编程基本功——C标准文件的读写操作示例

    源码

       1: #include <stdio.h>
       2: #include <string.h>
       3:  
       4: int main()
       5: {
       6:     FILE *fp;
       7:     char pathname[20], txt1[20]={'\0'}, txt2[20]={'\0'};
       8:     int nFileLen;
       9:  
      10:     printf("please input the path name of the file\n");
      11:     scanf("%s", pathname);
      12:     fp = fopen(pathname, "w");
      13:  
      14:     printf("please input a string to this file\n");
      15:     scanf("%s", txt1);
      16:     nFileLen = strlen(txt1);
      17:     fwrite(txt1, nFileLen, 1, fp);
      18:     fclose(fp);
      19:     printf("The file has been saved\n");
      20:  
      21:     printf("The content of the file: %s is \n", pathname);
      22:     fp = fopen(pathname, "r");
      23:     fread(txt2, nFileLen, 1, fp);
      24:     printf("%s\n", txt2);
      25:     fclose(fp);
      26:  
      27:     return 0;
      28: }
  • 相关阅读:
    精准测试
    git 管理
    git
    代码覆盖率测试
    vue 前端视频
    jenkins
    go学习资料
    4-4 求自定类型元素的平均
    4-3 简单求和
    4-2 多项式求值
  • 原文地址:https://www.cnblogs.com/steven_oyj/p/1742505.html
Copyright © 2011-2022 走看看