So, I noticed that my argc
is always 1
as I will always get the message Error: missing command line arguments!
, but as stated in code I am using argv[1]
and argv[2]
to read the files names.
Shouldn't automatically argc
be 3
in this case, and to be able to pass that error?
Notes:
- If I am not using
if (argc < 2)
statement, after I enter the name for the output file my program crushes. - For the input file I already have this one created in the project folder, so I just enter the name of that file.
This is the code:
#include <stdio.h>
#include <stdlib.h>
FILE *IN, *OUT;
int main(int argc, char* argv[])
{
if (argc < 2)
{
printf("Error: missing command line arguments!\n");
return 1;
}
printf("Enter the name of the file with the input data: ");
scanf("%s", argv[1]);
printf("\nEnter the name of the file for the output data: ");
scanf("%s", argv[2]);
IN = fopen(argv[1], "r");
OUT = fopen(argv[2], "w");
fclose(IN);
fclose(OUT);
return 0;
}