每日一题——第四十四题

题目: 将文本文件file1.dat的内容复制到文本文件file2.dat中,同时将文件中所有小写字母转换为大写字母

#include <stdio.h>  
#include <ctype.h> // 为了使用islower和toupper函数  
  
int main() {  
    FILE *file1 = fopen("file1.dat", "r"); // 打开file1.dat进行读取  
    if (file1 == NULL) {  
        perror("打开file1.dat失败");  
        return 1;  
    }  
  
    FILE *file2 = fopen("file2.dat", "w"); // 打开或创建file2.dat进行写入  
    if (file2 == NULL) {  
        fclose(file1); // 如果file2无法打开,先关闭file1  
        perror("打开或创建file2.dat失败");  
        return 1;  
    }  
  
    int ch; // 用于存储从file1.dat读取的字符  
    while ((ch = fgetc(file1)) != EOF) { // 逐个字符读取file1.dat  
        if (islower(ch)) { // 如果字符是小写字母  
            ch = toupper(ch); // 转换为大写字母  
        }  
        fputc(ch, file2); // 将处理后的字符写入file2.dat  
    }  
  
    fclose(file1); // 关闭file1.dat  
    fclose(file2); // 关闭file2.dat  
  
    return 0;  
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值