C++ File Handling: Convert Lowercase to Uppercase with fputc Example
This program opens a file named 's1.txt' in read mode, and a file named 'd1.txt' in write mode. It then reads each character of the input file one by one, and if the character is a lowercase letter, it converts it to uppercase by subtracting 32 from its ASCII code. It then writes the converted character to the output file.
However, there is an error in the code. In the line:
ch=fputc(fp2);
the fputc function is being called with only one argument, which is the file pointer to the output file. This is incorrect. The fputc function requires two arguments: the character to be written, and the file pointer to the output file. The correct line should be:
fputc(ch, fp2);
This will write the converted character to the output file.
原文地址: http://www.cveoy.top/t/topic/oljb 著作权归作者所有。请勿转载和采集!