16⁠ 2021-05-01 13:18 采纳率: 0%
浏览 200

使用fputs写入文件时报错?

代码如下

#include <stdio.h>
#include <string.h>
int main(void)
{
	char DestinationName[200];
	printf("请输入源文件的路径:");
	fgets(DestinationName, 199, stdin);
	*strchr(DestinationName, '\n') = '\0';
	FILE* Destination = NULL, * Target = NULL;
	if ((Destination = fopen(DestinationName, "r")))
	{
		char TargetName[200];
		printf("请输入目标文件路径:");
		fgets(TargetName, 199, stdin);
		*strchr(TargetName, '\n') = '\0';
		if ((Target = fopen(TargetName, "r+")))
		{
			char temp1[100], temp2[100];
			long Location[2];
            //fputs("cs", Target);在此处执行无任何问题
			while (fgets(temp1, 100, Destination) && fgets(temp2, 100, Target))
			{
				Location[0] = strlen(temp1);
				Location[1] = strlen(temp2);
				fputs("cs", Target);//执行到此处Vs会有个报错 但是使用其他软件执行不会报错但是没有任何效果	
			}
			if (fclose(Target))
				fprintf(stderr, "目标文件关闭失败!");
		}
		else
			fprintf(stderr, "目标文件打开失败!");
		if (fclose(Destination))
			fprintf(stderr, "源文件关闭失败!");
	}
	else
		fprintf(stderr, "源文件打开失败!");
	return 0;
}

报错内容

Microsoft Visual C++ Runtime Library

Debug Assertion FailediProgram: F:\Vs2019\项目\Update'\Debug\Update.exeFile: minkernel\crts\ucrt\src\appcrt\ stdio\fwrite.cpp Line: 88

Expression: ("Flush between consecutive read and write.".!stream.has any of( IOREAD)

For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)

  • 写回答

5条回答 默认 最新

  • CSDN专家-三岁丫 2021-05-01 13:31
    关注

    如果使用 r+ 的话,目的文件必须要存在。

    评论

报告相同问题?

悬赏问题

  • ¥15 C++为什么这个代码没报错运行不出来啊
  • ¥15 为什么跑这个代码,文件显示不在呀
  • ¥15 一道ban了很多东西的pyjail题
  • ¥15 关于#r语言#的问题:如何将生成的四幅图排在一起,且对变量的赋值进行更改,让组合的图漂亮、美观@(相关搜索:森林图)
  • ¥15 C++识别堆叠物体异常
  • ¥15 微软硬件驱动认证账号申请
  • ¥15 GPT写作提示指令词
  • ¥20 根据动态演化博弈支付矩阵完成复制动态方程求解和演化相图分析等
  • ¥15 华为超融合部署环境下RedHat虚拟机分区扩容问题
  • ¥15 哪位能做百度地图导航触点播报?