小写字符在C和大写字符;写入文件

编程入门 行业动态 更新时间:2024-10-28 00:24:32
本文介绍了小写字符在C和大写字符;写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我读的内容读入C中的字符数组我怎么会改变所有的文件中是小写字母为大写字母的信吗?

I am reading content from a file to be read into a char array in C. How could I change all the letters in the file that are lowercase to uppercase letters?

推荐答案

下面是一个可能的算法:

Here's a possible algorithm:

  • 打开一个文件(我们称之为A) - fopen()函数
  • 打开另一个文件中写入(我们称之为B) - fopen()函数
  • 阅读A的含量 - GETC()或FREAD();不管你觉得自由
  • 请您阅读大写的内容 - TOUPPER()
  • 写了4步到B的结果 - FWRITE()或fputc()函数或fprintf中()
  • 关闭所有文件句柄 - FCLOSE()
  • 下面是用C语言编写的code:

    The following is the code written in C:

    #include <stdio.h> #include <ctype.h> #define INPUT_FILE "input.txt" #define OUTPUT_FILE "output.txt" int main() { // 1. Open a file FILE *inputFile = fopen(INPUT_FILE, "rt"); if (NULL == inputFile) { printf("ERROR: cannot open the file: %s\n", INPUT_FILE); return -1; } // 2. Open another file FILE *outputFile = fopen(OUTPUT_FILE, "wt"); if (NULL == inputFile) { printf("ERROR: cannot open the file: %s\n", OUTPUT_FILE); return -1; } // 3. Read the content of the input file int c; while (EOF != (c = fgetc(inputFile))) { // 4 & 5. Capitalize and write it to the output file fputc(toupper(c), outputFile); } // 6. Close all file handles fclose(inputFile); fclose(outputFile); return 0; }

    更多推荐

    小写字符在C和大写字符;写入文件

    本文发布于:2023-11-12 11:29:58,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1581379.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:字符   文件

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!