Retail Outlet Managment System
Hi Board,
I am aware of the thread that already exists on this subject, but it hasn't been able to help me with the problems that I am experiencing. Thus, I decided to create a thread of my own. Basically, I'm having trouble understand the concept of reading information from a file. Does the file need to apart of the C project or just in the same location as the source file? I'm assuming that it just needs to be in the same location..
The other problem that I am experiencing is printing the values scanned from the file. Here is what I have coded so far:
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX_TBL_SIZE 30
void printCurrentStatus();
int main() {
char filename[20];
printf("Enter the name of the input file:\n");
scanf("%s", &filename);
printCurrentStatus();
system("PAUSE");
return(0);
}
void printCurrentStatus() {
FILE *ifp;
int input_item_id[MAX_TBL_SIZE], input_item_stock[MAX_TBL_SIZE];
float unit_price[MAX_TBL_SIZE];
ifp = fopen("retail.txt", "r");
while((input_item_id[MAX_TBL_SIZE] != 0)||(input_item_stock[MAX_TBL_SIZE] != 0)||(unit_price[MAX_TBL_SIZE] != 0)) {
fscanf(ifp, "%d", &input_item_id[MAX_TBL_SIZE]);
fscanf(ifp, "%d", &input_item_stock[MAX_TBL_SIZE]);
fscanf(ifp, "%f", &unit_price[MAX_TBL_SIZE]);
}
fclose(ifp);
printf("\n Current Status \n");
printf("Id Stock Price Sufficient\n");
}
When I try to use the printf statement for each of the three arrays, nothing prints to the screen. However, my program runs smoothly with no errors whatsoever. If someone could help to explain to me how to print values from a file properly, I would greatly appreciate it. Thanks in advance!
- Hugh