d2jsp
d2jsp Forums > Off-Topic > Programmer's Haven > C/C++/C# > C Cmd Args And File I/o
Add Reply New Topic New Poll
Jay255
Group: Member
Posts: 8,820
Joined: May 10 2009
Gold: 1,185.00
Apr 6 2022 02:56pm
so I'm trying to set my file modes with command line arguements, and with this conditional statement the program isn't working as intended. But without conditions, it's fine, any ideas?

int main(int argc, char *argv[]) {
FILE* outfil;
FILE* infil;

if(strcmp(argv[1], "-i") == 0){
infil = fopen(argv[2], "r");
outfil = fopen(argv[4], "w");

}

else if(strcmp(argv[3], "-i") == 0){
outfil = fopen(argv[2], "w");
infil = fopen(argv[4], "r");

}

else{
printf("Invalid command line usage.");
return 1;
}
}
k13ss
Group: Member
Posts: 171
Joined: Mar 24 2022
Gold: 141.00
May 26 2022 02:04pm
Can you write your input arguments and expectations?
Go Back To C/C++/C# Topic List
Add Reply New Topic New Poll