c - 在c中读取和写入文本文件
问题描述
一个简单的程序,用于对文本文件执行写入操作,然后从文件中读取并显示文本。我该如何纠正它以及如何避免使用“#define _CRT_SECURE_NO_WARNINGS”我正在使用visual studios 2018我已经尝试了多次但输出似乎无限输出
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
void main()
{
FILE *fp1, *fp2;
fp1 = fopen("text.txt", "w");
printf("enter no of lines");
int line;
scanf("%d", &line);
char txt[1000];
for (int i=0; i < line; i++)
{
gets( txt);
fprintf(fp1, "s", txt);
}
fclose(fp1);
char txt2[1000];
fp2 = fopen("text.txt", "r");
while (1)
{
fgets(txt2, 1000, fp2);
if (txt2 == EOF)
break;
printf("%s", txt2);
}
fclose(fp2);
}`
解决方案
推荐阅读
- python-3.x - 使用 spyder IDE 在 python 3.6 中的单个 if 语句中测试多个条件的语法
- kotlin - 在 Spring Rest Docs 中添加基本 url 的路径?
- python - 当某些 Windows 有焦点时,Python 不会检测到击键
- html - 在 Electron 中单击按钮时运行脚本
- ssh - 使用 sshfs Visual Studio 代码连接到 ssh
- python - Discord.py v3(重写)尝试将用户输入与预设元组列表匹配
- python - 在python烧瓶中将结果转换为json
- parquet - 使用从 parquet 文件创建的 dask 数据帧时使用过多的内存
- react-native - 安装 React-Native-firebase 后无法运行项目
- google-cloud-platform - 将谷歌数据工作室连接到谷歌云 sql