Thanks for all the help so far.
I am now trying to scanf the file in a sturcture called det and then add up some of the vlues from the stucture but when i run the program ,my compiler is basically crashing.
A can't seem to find the problem.
Code:void displayreport(void) { FILE *doc; int found =0,fees=0,collected=0,health=0; doc=fopen("transaction.txt","r"); if (doc==NULL) printf("\n\n\t\t FILE NOT FOUND"); else { while(!feof(doc)) { fscanf(doc,"%s %s %s %s %s %d %d %d %d",det.name,det.regis,det.pname,det.treatment,det.piont,det.fees,det.collect,det.insure,det.balance); found++; fees = det.fees + fees; collected = det.collect + collected; health = det.insure + health; } } printf("\n\n\t\t THE INCOME REPORT IS GENERTATED BELOW IS:\n"); printf("\n\t\t THE NUMBER OF PATIENTS ARE:%d",found); printf("\n\t\t TOTAL FEES ARE:$ %d",fees); printf("\n\t\t TOTAL FEES COLLECTED:$ %d",collected); printf("\n\t\t TOTAL HEALTH INSURANCE FEES:$ %d",health); fclose(doc); }
What does the compiler output?
basically its crashing and trying to find a solution the the problem. i am getting nothing
What compiler are you using?
Correctly use *scanf arguments -- provide a pointer where pointers are expected.
Avoid loop control using eof.
Something like this:
Code:while ( fscanf(doc, "%s %s %s %s %s %d %d %d %d", det.name, det.regis, det.pname, det.treatment, det.piont, &det.fees, &det.collect, &det.insure, &det.balance) == 9 ) { found++; /* ... */As an aside, learn to describe better what you are talking about. There is compile time, link time, and run time. If if compiles, the "compiler is basically crashing" is terribly wrong. When it compiles fine and links fine, then you've got a run time error. Telling people that it's a compiler issue will only get you further from an answer -- so don't make things up. Run time issues are a different set of problems with different solutions; if you don't know what you're talking about, try to post only what you do know. ;Pbut when i run the program ,my compiler is basically crashing.
I was trying to get him to figure that out himself.Telling people that it's a compiler issue will only get you further from an answer -- so don't make things up. Run time issues are a different set of problems with different solutions; if you don't know what you're talking about, try to post only what you do know. ;P![]()
Thanks a lot, and also for the explanation. now i realized it was definitely a run time error.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks