-
need help with debugging
Im a big programming newbie and need to get my program running for my class programing project.
Code:
#include <stdio.h>
//function declarations
int getreport (FILE* spIN,
int* partnum, int* price,
int* qty, int* reorder, int* minorder);
int writereport (FILE* spOUT, int partnum, int price, int qty,
int reorder, int minorder, int* orderamt);
void calcorderamount (int reorder, int minorder);
int main(void)
{
//local declarations
FILE* spIN;
FILE* spOUT;
int partnum;
int price;
int qty;
int reorder;
int minorder;
int* orderamt;
//statements
printf("begin inventory report\n\n");
spIN = fopen ("C:\\stuff.TXT", "r");
if (!(spIN = fopen ("C:\\stuff.TXT", "r")))
{
printf("error opening stuff.txt\n");
return 101;
}//input file error check
if (!(spOUT = fopen ("C:\\inventoryreport.TXT", "w")))
{
printf("error creating inventory file\n");
return 102;
}//output file error check
while (getreport
(spIN, &partnum, &price, &qty, &reorder, &minorder))
{
calcorderamount (reorder, minorder);
writereport (spOUT, partnum, price, qty, reorder, minorder, orderamt);
}//while
fclose (spIN);
fclose (spOUT);
printf ("end of inventory report\n");
return 0;
}
int getreport (FILE* spIN, int* partnum, int* price,
int* qty, int* reorder)
{
//local declarations
int ioresult;
int minorder;
//statements
ioresult = fscanf(spIN, "%d%f%d%d%d", partnum,
price, qty, reorder, minorder);
if (ioresult == EOF)
return 0;
else if (ioresult !=5)
{
printf("\aError reading data\n");
return 0;
}//error check
else
return 1;
}
void calcorderamount (int reorder, int minorder)
{
//statements
int* orderamt;
int* qty;
*orderamt = (reorder + minorder);
if (*qty < *reorder)
*qty = *orderamt;
else
*qty = *qty;
return;
} //clacgrade
int writereport (FILE* spOUT, int partnum, int price, int qty,
int reorder, int minorder, int orderamt)
{
//statements
fprintf(spOUT, "%d %f %d %d %d %d", partnum,
price, qty, reorder, minorder, orderamt);
return 0;
}//writereport
it's sloppy i know. but i can't figure out that "illegal indirection" error at my if else statement.
i am using visual c++ 2005 express edition as a compiler (and my professor said ONLY to use this compiler).
Help will be MUCH appreciated.
edit: here is what i am trying to accomplish: when the quantity on hand (qty) falls below the reorder point (reorder), it adds the minimum order (minorder) to the reorder point to produce the order amount (orderamt). otherwise, the quantity on hand is left alone and reprinted in the order amount.
-
It helps if you actually tell us where you're getting the error. But:
Code:
void calcorderamount (int reorder, int minorder)
{
//statements
int* orderamt;
int* qty;
*orderamt = (reorder + minorder);
if (*qty < *reorder)
*qty = *orderamt;
else
*qty = *qty;
return;
} //clacgrade
Neither of those pointers actually point anywhere. reorder isn't a pointer. Also, what is your else supposed to be doing?
Quzah.
-
opps. i left out some info. read the bottom of the first post
-
The same problem is still there.
orderamt and qty point to nowhere.
-
@Wiggles, If you enable your compiler warnings to maximum and pay attention to them, half of your bugs might have been spotted. You may want to use lint also.