Hi,
I am having problems with this program. I am not gettting any errors but it just sits there and does nothing. It's a Product Inventory program. I am supposed to read an Input file and display it on the screen then write to an outfile. Here is my code, any help would be appreciated.
Thank you,
Jay
Code:
/*Libraries included*/
# include <stdio.h>
/*main Function*/
int main()
{
FILE *inFile;
FILE *outFile;
int i;
char allIn[16] = {0};
char yearMonth[6] = {0};
int month;
char *monthWord[12];
int cdId;
int begBal;
int copRec;
int copSold;
int endBal;
int year;
/*Open Input File*/
if ((inFile = fopen("input.txt", "r")) == NULL)
{
printf("\nFailed to open the data file named %s. \n", inFile);
exit(1);
}
while (fgets(yearMonth,6,inFile) != NULL)
sscanf(yearMonth, "%4d%2d", &year, &month);
for (i = 0; i <= 8; ++i)
{
while (fgets(allIn,16,inFile) != EOF)
sscanf(allIn,"%4d%4d%4d%4d",&cdId, &begBal, &copRec, &copSold);
/*change month int to month name*/
if (month == 01)
monthWord[0] = "January";
else if (month == 02)
monthWord[1] = "February";
else if (month == 03)
monthWord[2] = "March";
else if (month == 04)
monthWord[3] = "April";
else if (month == 05)
monthWord[4] = "May";
else if (month == 06)
monthWord[5] = "Jume";
else if (month == 07)
monthWord[6] = "July";
else if (month == 8)
monthWord[7] = "August";
else if (month == 9)
monthWord[8] = "September";
else if (month == 10)
monthWord[9] = "October";
else if (month == 11)
monthWord[10] = "November";
else if (month == 12)
monthWord[11] = "December";
else
printf("That is not a month determiner\n");
fclose(inFile);
/*Open the output file*/
if ((outFile = fopen("output.txt", "a")) == NULL)
{
printf("\nFailed to open the data file named %s. \n", outFile);
exit(1);
}
fprintf(outFile,"\n\n CD INVENTORY REPORT FOR %20s %4d\n\n", monthWord, year);
fprintf(outFile," Beginning Copies Ending\n");
fprintf(outFile,"CD ID Balance Received Copies Sold Balance\n");
fprintf(outFile,"___________________________________________________________________________\n");
/*loop to print Structure*/
for (i = 0; i <= 8; ++i)
printf("%4d %4d %4d %4d %4d\n", cdId, begBal, copRec, copSold, endBal = begBal + copRec - copSold);
fprintf(outFile,"%4d %4d %4d %4d %4d\n",cdId, begBal, copRec, copSold, endBal);
fclose(outFile);
printf(" CD INVENTORY REPORT FOR %20s %4d\n\n", monthWord, year);
printf(" Beginning Copies Ending\n");
printf("CD ID Balance Received Copies Sold Balance\n");
printf("___________________________________________________________________________\n");
}
return 0;
}