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

使用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+ 的话,目的文件必须要存在。

    评论

报告相同问题?

悬赏问题

  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名