Well im trying to create a program to do a program for a store, but im stuck when trying to input and read prices from a text file. As you can see from the menu i have alot to do. Any help and advice would be appreciated. I put the main() infront of the change price function to see if it was working.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
/*char menu
{
int choice
while(choice != 'e')
printf("Welcome to the REGISTER 2000\n");
printf("Choose the corresponding letter to choose the option you desire");
printf("a. Payment\n");
printf("b. Change price\n");
printf("c. Veiw stock\n");
printf("d. Add stock\n");
printf("e. Exit");
fflush(stdout);
scanf("%c", &choice);
}
int password
{
char userid[]="zion",password[]="zionatscodz",p[15],u[15];
int n=1,a,b;
printf("Enter USER ID and PASSWORD below (You have only three chances to enter)\n");
getchar();
while(n<=3)
{
printf("\nUSER ID: ");
scanf("%s",u);
printf("\nPASSWORD: ");
scanf("%s",p);
a=strcmp(u,userid);
b=strcmp(p,password);
if(a==0&&b==0)
{
printf("You have logged in successfully.\n");
break;
}
else
{
printf("Wrong PASSWORD and/or USER ID. Now you have %d more chances ", 3-n);
}
getchar();
n++;
}
if(n==4)
printf("You can't log in.\n");
getchar();
}
*/
main()
{
int i;
int price;
char item[10];
FILE * fp =fopen("price list.txt","a");
if(!fp)
{
printf("the file could not be found, create a file\n");
getchar();
return 1;
}
printf("Input prices\n");
for (i=1;i<=10;i++)
{
fscanf(stdin,"%s%d",item,&price);
fprintf(fp,"%s%d",item,&price);
}
fclose (fp);
fprintf(stdout,"\n\n");
fp=fopen("price list.txt","a");
printf("Item price");
for(i=1;i<=10;i++)
{
fscanf(fp,"%s%d%",item,&price );
fprintf(stdout,"%s%d\n",item, price);
}
fclose(fp);
system("PAUSE");
}