#include<stdio.h>
#include<stdlib.h>
int main(int argc, char *argv[])
{
FILE *source_fp, *content_fp;
int ch;
if(!(source_fp=fopen(argv[1],"wb")))
{
printf("can't open file\n");
return 0;
}
for(int i = 2 ; i < argc ; i++)
{
if(!(content_fp=fopen(argv[i],"r")))
printf("can't find file%s\n", argv[i]);
else
{
while(ch = fgetc(source_fp))
{
fputc(ch,source_fp);
}
fclose(content_fp);
}
}
fclose(source_fp);
}
I get the following error messages when running this program:
Debug Assertion Failed!
Program: ...ments\Visual Studio 2015\Projects\Project9\Debug\Project9.exe File: minkernel\crts\ucrt\src\appcrt\stdio\fopen.cpp Line: 30
Expression: file_name != nullptr
For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
How do I fix this issue?
file_name = nullptr? Must be MSVC. And you're not checking ifargv[1]is non-null. - Andrew Henleargcis at least 2 (i.e. you don't check ifargv[1]is valid). - Kevinargc > 2and exit if it isn't before you try to open the first file. - wizzwizz4