代码如下
#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)