1. From the keypad to enter a string, all lowercase letters to uppercase letters, and then output to a disk file "test" to save.
Enter a string! End
#include<stdio.h>
#include<stdlib.h>
int main() {
char ch;
FILE *fp;
fp = fopen("E:\\test.txt","w");
if(!fp) {
printf("文件不存在");
exit(0);
}
printf("请输入一个字符串并且以!结束:\n");
ch = getchar();
while(ch != '!') {
if(ch >='a' && ch <= 'z') {//小写字母转大写字母
ch-=32;
}
fputc(ch,fp);
putchar(ch); // 将输出的字符显示在屏幕上
ch=getchar(); // 再接收从键盘输入的一个字符(不加这句话会出现死循环)
}
fclose(fp);
}
【operation result】
(1) In the console displays the results
(2) results in the input file