command line input problem
I am getting a "memory could not be written" when gets for file-out name. When a user only enters file-in name, the program prompts for output file name. When user enters it, it gets the string and puts it in argv[2] and this is where I get the error.
void
main(int argc, char *argv[])
{
char fileNameIn[20];
char fileNameOut[20];
if(argc == 1) // only the program name is input
{
printf("\n Usage: pgm10 input_fileName output_fileName\n");
exit(1);
}
if (argc == 2) // two strings input(pgm10 and input
// fileName); output fileName is missing
{
fflush(stdin);
printf("\n Please enter output file name: ");
gets(argv[3]);
}
printf("file name in = %s\n", argv[2]);
printf("file name out = %s\n", argv[3]);
}