I'm trying to compile the following code. When I give input to the program then after pressing enter a popup appears which shows that
store program.exe has stopped working
Note: I am using Windows 8.1
Note: I am working on a program (which used in super stores), which includes the following things:
- Product code
- Product name
- Product price
- Total bill calculations
It's just the starting.
#include <stdio.h>
int main (void)
{
int d, code;
char product[100], price[100];
printf("\t\t Welcome to the Metro Store\n\n\n\n Enter your product code: ");
scanf("%d",code);
if(code<100)
printf("Pharmacy\n Name of the Medicine");
fflush(stdout);
fgets(product, 100, stdin);
printf(product);
return 0;
}
For starters you should try
You have to tell scanf where to write to. If you don't specify the ampersand (&), scanf will not know where is should write to.
You should read the docs and definitely a good introduction to pointers. If you don't understand pointers, programming in C and C++ is pointless ;-)
Then you can change your
fgets()
toscanf( "%s", product );
In this case scanf does not need the
&
becauseproduct
is short for&product[0]
. This can get rather confusing, so get to grips with pointers before continuing.