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("c\\report.txt", "w"
;
inputfile = fopen("c:\\input.txt", "r"
;
//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, "The MoneyMaking Corporation"
;
fprintf(outputfile, "\n550 Warm Sands Drive"
;
fprintf(outputfile, "\nPalm Springs, CA\n\n"
;
fprintf(outputfile, "Type Amount Net\n"
;
fprintf(outputfile, "---- ------ ---\n"
;
fclose(outputfile);
}
//does calculations and prints data to outputfile
void data (void)
{
while (!feof(outputfile))
{
fgets(trantype, 6, inputfile);
fscanf(inputfile, "%f\n", &value);
runtotal = (runtotal + value);
fprintf(outputfile, "%-35s%10.2f%12.2f\n", trantype, value, runtotal);
transtotal = transtotal + 1;
nettotal = nettotal + value;
fprintf(outputfile, "The net total for the month is %.0f\n", nettotal);
fprintf(outputfile, "\nTransactions proccessed: %d\n", transtotal);
}
}
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("c\\report.txt", "w"
inputfile = fopen("c:\\input.txt", "r"
//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, "The MoneyMaking Corporation"
fprintf(outputfile, "\n550 Warm Sands Drive"
fprintf(outputfile, "\nPalm Springs, CA\n\n"
fprintf(outputfile, "Type Amount Net\n"
fprintf(outputfile, "---- ------ ---\n"
fclose(outputfile);
}
//does calculations and prints data to outputfile
void data (void)
{
while (!feof(outputfile))
{
fgets(trantype, 6, inputfile);
fscanf(inputfile, "%f\n", &value);
runtotal = (runtotal + value);
fprintf(outputfile, "%-35s%10.2f%12.2f\n", trantype, value, runtotal);
transtotal = transtotal + 1;
nettotal = nettotal + value;
fprintf(outputfile, "The net total for the month is %.0f\n", nettotal);
fprintf(outputfile, "\nTransactions proccessed: %d\n", transtotal);
}
}