我正在创建一个程序,它从一个文本文件中读取数据并将其大小更改为大写或小写,然后将该数据存储在新文件中.我搜索过互联网,但我找不到如何创建新的文本文件.
#include <stdio.h>
int main(void) {
FILE *fp = NULL;
fp = fopen("textFile.txt" ,"a");
char choice;
if (fp != NULL) {
printf("Change Case \n");
printf("============\n");
printf("Case (U for upper, L for lower) : ");
scanf(" %c", &choice);
printf("Name of the original file : textFile.txt \n");
printf("Name of the updated file : newFile.txt \n");
Run Code Online (Sandbox Code Playgroud)
我知道这是不完整的,但我无法弄清楚如何创建一个新的文本文件!
fp = fopen("textFile.txt" ,"a");
Run Code Online (Sandbox Code Playgroud)
这是创建文本文件的正确方法.问题出在你的printf陈述上.你想要的是:
fprintf(fp, "Change Case \n");
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
41053 次 |
| 最近记录: |