Hi,
This is my first post in this forum and it is a 'help me' post :)
Anyway, I took a beginners class in C Programming and at the completion of the class we were assigned to do a project. The project is designing a billing system for a supermarket. Note : I am not here to ask you guys to do my project for me, that would be cheating :P
So, I have a question about some of the functions the program should do.
We are supposed to create a text file to store all the records of the stocks and quantities etc. of the supermarket. Now for adding these stocks, i have used this code,
void add()
{
clrscr();
int item_code = 0;
char item_name[80];
int qihand;
int item_quantity;
float item_cost;
printf("Addition Page Test");
FILE *quantity;
if((quantity = fopen("C:\\TEST\\XYZ\\quantity.dat","a+"))==NULL)
item_code=1;
else
{
do{
fscanf(quantity,"\n %i %[^/]%*c %i %f", &item_code, &item_name, &qihand, &item_cost);
} while (!feof(quantity));
item_code+=1;
}
printf("\nItem Code : %i", item_code);
printf("\nEnter Item Name :");
gets(item_name);
printf("\nEnter The Quantity :");
scanf ("%i",&qihand);
printf("\nEnter The Price Per Unit :");
scanf("%f",&item_cost);
printf("\nRecord Added To Database");
fprintf(quantity, "\n %i %s %i %.2f", item_code, item_name, qihand, item_cost);
fflush(stdin);
getch();
fclose(quantity);
menu();
}
Now, this actually works good until i get to the 3rd item to be added on to my text file. The thing is eventhough from what I understand, the new "item_code" should automatically be updated according to the last "item_code" that is present in the text file when entering a new record, it just stays at "2" no matter how many items i enter. Also, all the records gets saved in the text file fine.
So could someone help me get this numbering thing flowing.. it maybe a small tiny line i maybe missing due to my amaturishness...
Also, I was wondering if there was any easier way to use to add records to a text file.
Thanks alot for the help ! Its greatly appreciated.