从键盘输入一个字符串,将其中的小写字母全部转换成大写字母,然后输出到一个 磁盘文件test中保存,输入的字符串以"!"结束
#include <stdio.h>
#include <ctype.h>
int main() {
FILE *file;
char ch;
file = fopen("test.txt", "w");
if (file == NULL) {
printf("无法创建文件!\n");
return 1;
}
printf("请输入字符串(以'!'结束):\n");
while ((ch = getchar()) != '!') {
if (islower(ch)) {
ch = toupper(ch);
}
fputc(ch, file);
}
fclose(file);
printf("字符串已保存到test.txt文件中。\n");
return 0;
}