zoukankan      html  css  js  c++  java
  • C语言程序设计 练习题参考答案 第八章 文件(1)

    /* 8.5 从键盘输入一行字符,将其中小写字母转换为大写字母 */
    #include "stdio.h"
    void main()
    {
        FILE *fp;
        char ch;
        if((fp=fopen("c:\\ex85.txt","w"))==NULL)
          {
           printf("不能创建文件c:\\ex85.txt");
           exit(1);
          }
        printf("请输入一行字符\n");
        while((ch=getchar())!='\n')
          {
            if(ch>='a' && ch<='z')
               ch=ch-32;
            fputc(ch,fp);
          }
        fclose(fp);
        printf("操作成功");
    }
     /* 8.7  把一个ASCII文件连接在另外一个ASCII文件之后。 把c:\\ex87_1.txt中的字符连接在c:\\ex87_2.txt中的之后*/
    #include "stdio.h"
    void main()
    {
        FILE *fp1,*fp2;
        char ch;
        if((fp1=fopen("c:\\ex87_1.txt","r"))==NULL)
          {
           printf("不能打开文件c:\\ex87_1.txt");
           exit(1);
          }
        if((fp2=fopen("c:\\ex87_2.txt","a"))==NULL)
          {
           printf("不能打开文件c:\\ex87_2.txt");
           exit(1);
          }
        while((ch=fgetc(fp1))!=EOF)
          {
            fputc(ch,fp2);
          }
        fclose(fp1);
        fclose(fp2);
        printf("操作成功,请打开c:\\ex87_2.txt查看结果");
    }
  • 相关阅读:
    AtCoder Beginner Contest 218 A~F 题解
    【学习笔记】光速幂
    【Nowcoder 1103A】复读数组
    【Nowcoder 1105A】集合统计
    初赛知识宝典
    KMP算法 next数组模板
    C#链接Windows远程桌面
    帝国cms 修改 上一篇 下一篇样式
    Appweb漏洞复现
    Apereo-cas漏洞复现
  • 原文地址:https://www.cnblogs.com/emanlee/p/1202084.html
Copyright © 2011-2022 走看看