本文介绍了小写字符在C和大写字符;写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
打开一个文件(我们称之为A) - fopen()函数 打开另一个文件中写入(我们称之为B) - fopen()函数 阅读A的含量 - GETC()或FREAD();不管你觉得自由 请您阅读大写的内容 - TOUPPER() 写了4步到B的结果 - FWRITE()或fputc()函数或fprintf中() 关闭所有文件句柄 - FCLOSE()
我读的内容读入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:
下面是用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和大写字符;写入文件
发布评论