I had a feeling it was wrong. sorry MK27
anyway, I have redone the code. So what do you think of this?
Code:
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string.h>
struct item {
int ID;
char name[64];
int price;
int main(int argc, char *argv)
FILE *fp;
char retstr[BUFSIZ];
char *f1, *f2, *f3, *p;
int max_cnt=15;
int i, cnt=0;
struct item record [50]
fp = fopen("C://shoppinglist.txt","r");
if(file==NULL) {
printf("Error: can't open file.\n");
return 1;
}
else {
printf("File opened successfully.\n");
while (retstr, BUFSIZ, fp)!= NULL) {
{
if ((p = strchr(retstr, '\n')) != NULL)
*p = '\0';
if(cnt == max_cnt)
break;
f1=strtok(retstr, " ");
f2=strtok(NULL, " ");
f3=strtok(NULL, " ");
strcpy(usr[cnt].ID, f1);
strcpy(usr[cnt].name, f2);
strcpy(usr[cnt].price, f3);
cnt++;
}
for(i=0; i < cnt; i++)
printf("%d %s %d\n", record[i].ID, record[i].name,record[i].price);
fclose(fp);
exit(0);
}
printf( "1 - view the complete list of goods in the shop, with their prices" );
printf( "2 – list the cheapest item on offer" );
printf( "3 – “discount” option" );
printf( "4 – choose items for purchase" );
printf( "5 – total price for items" );
printf( "6 - Exit");
switch ( option ) {
case 1:
case 2:
break;
case 3:
case 4:
printf( "choose item for purchase\n" );
break;
case 5:
printf( "total price for items\n" );
break;
case 6:
printf( "Exit\n" );
}
return 0;
[