c - Same name input/output issue -



c - Same name input/output issue -

okay guys, i'm having 1 more issue program. i'm running issue using same filename (knightsball."extension"). don't know if it's locally, or issue i'll have when move code over. can help me thing i'm overlooking? output , input have both go same filename.(in) or (out) no ways around. if alter output file knights.out works. ideas? relevant segments of code:

file *fr; file *fo; typedef struct knightsballlottoplayer { char firstname[20]; char lastname[20]; int numbers[6]; } kblottoplayer; int main() { kblottoplayer *temp; int numplays=0; //what file read fr = fopen("knightsball.in", "r"); //what file read fo = fopen("knightsball.out", "w");

and part output accessed:

if(match==3) fprintf(fo,"%s %s matched %d numbers , won $10.\n", temp[r].firstname, temp[r].lastname, match); if(match==4) fprintf(fo,"%s %s matched %d numbers , won $100.\n", temp[r].firstname, temp[r].lastname, match); if(match==5) fprintf(fo,"%s %s matched %d numbers , won $10000.\n", temp[r].firstname, temp[r].lastname, match); if(match==6) fprintf(fo,"%s %s matched %d numbers , won $1000000.\n", temp[r].firstname, temp[r].lastname, match);

also on unrelated side note, know how close command prompt after scan in values need user? help much appreciated.

since don't show code check opened each file successfully, probable didn't open output file. not clear why, 1 possible problem output file exists , read-only. might don't have permission create files in directory.

i can't help think utilize array of strings cut down printing to:

static const char *amounts[] = { "", "", "", "10", "100", "10000", "1000000" }; if (match >= 3 && match <= 6) fprintf(fo, "%s %s matched %d numbers , won $%s.\n", temp[r].firstname, temp[r].lastname, match, amounts[match]);

since there isn't simple relation between values, best utilize table rather calculation amounts.

c input io

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -