d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > C Cmd Args And File I/o
Add Reply New Topic New Poll
Member
Posts: 8,842
Joined: May 10 2009
Gold: 118.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;
}
}
Member
Posts: 172
Joined: Mar 24 2022
Gold: 131.00
May 26 2022 02:04pm
Can you write your input arguments and expectations?
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll