Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Errors upon running program

Status
Not open for further replies.

NEFJ

MIS
Dec 15, 2001
33
0
0
US
Hey guys/gals,

I could use a bit of help with some problems im having with a assignment. Please forgive my ignorance when it comes to C I am just starting out. I get my code to compile fine but when I run the app it crashed with the message below. This is the second program that its happend I still have not resolved the error with the first program either.

If it matters I am using Borland 5.02 on Windows XP Pro

Here is the error:

"Fault Access Violation at 0x404664: read of address Ox12"

Ive also included the ugly code for the app any suggestions on making it better would always be appreciated. Thanks much - NJS

#include <stdio.h>
#include <math.h>


//Declare variables
FILE *inputfile; //file that will be used for input
FILE *outputfile; //file that will be used for output
float nettotal; //total of all transactions
float value; //value of a particular transaction
float net; //total of transactions
float runtotal; //net colum running total
int transtotal; //total number of transactions
char trantype[6]; //declares import or export

void header(void);
void data (void);

//****Main Function****

int main (void)
{

//opens files needed for operation
outputfile = fopen(&quot;c\\report.txt&quot;, &quot;w&quot;);
inputfile = fopen(&quot;c:\\input.txt&quot;, &quot;r&quot;);

//initilize variables
nettotal = 0.0;
transtotal = 0;
runtotal = 0.0;


header();
data();


fclose(inputfile);
fclose(outputfile);

return 0;

}

//prints a header file into the outputfile
void header (void)
{

fprintf(outputfile, &quot;The MoneyMaking Corporation&quot;);
fprintf(outputfile, &quot;\n550 Warm Sands Drive&quot;);
fprintf(outputfile, &quot;\nPalm Springs, CA\n\n&quot;);
fprintf(outputfile, &quot;Type Amount Net\n&quot;);
fprintf(outputfile, &quot;---- ------ ---\n&quot;);
fclose(outputfile);
}

//does calculations and prints data to outputfile
void data (void)
{
while (!feof(outputfile))
{
fgets(trantype, 6, inputfile);
fscanf(inputfile, &quot;%f\n&quot;, &value);
runtotal = (runtotal + value);
fprintf(outputfile, &quot;%-35s%10.2f%12.2f\n&quot;, trantype, value, runtotal);


transtotal = transtotal + 1;
nettotal = nettotal + value;

fprintf(outputfile, &quot;The net total for the month is %.0f\n&quot;, nettotal);
fprintf(outputfile, &quot;\nTransactions proccessed: %d\n&quot;, transtotal);
}
}

 
Should 'while (!feof(outputfile))' really refer to
the output file ? Testing for EOF on the input file
seems more logical.
 
Yeah in addition top that check for null returns with file i/o functions. R.Sathish.
babusats@rediffmail.com

 
are we closing the output before we are finished

void header (void)
{

fprintf(outputfile, &quot;The MoneyMaking Corporation&quot;);
fprintf(outputfile, &quot;\n550 Warm Sands Drive&quot;);
fprintf(outputfile, &quot;\nPalm Springs, CA\n\n&quot;);
fprintf(outputfile, &quot;Type Amount Net\n&quot;);
fprintf(outputfile, &quot;---- ------ ---\n&quot;);

// what happens here????????????????????
fclose(outputfile);
}

 
Thanks for all of your help, All of the things you guys mentioned helped

The error was being caused by a typo in the opening of the report file.

I missed a : after the c

//opens files needed for operation
outputfile = fopen(&quot;c\\report.txt&quot;, &quot;w&quot;);
inputfile = fopen(&quot;c:\\input.txt&quot;, &quot;r&quot;);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top