I'm required to do a seafood menu as an assignment in my college. I will provide the relevant code here:
int main ()
{
int a,d;
float c ;
char b,s,S,m,M,l,L;
printf ("\n\t\t\t\tSeafood Menu\n");
printf ("----------------------------------------------------------------------------------\n");
printf ("\t\t\t\t\t\t Dish Size\n");
printf ("Item Number\t Seafood Dish\t Small\t Medium Large\t\n");
printf ("----------------------------------------------------------------------------------\n");
printf ("\t 1\t Fried \t20.00 \t\t 40.00 \t\t 55.00\n");
//Continue with a bunch of menu here
printf (" Enter item number :");
scanf ("%d",&a);
printf (" Enter dish size (S/M/L) :");
scanf ("%s",&b);
if ((a==1)&&((b=='s')||(b=='S')))
{c=20.00;}
//continue with a bunch of condition to choose the price per dish stated in the menu
printf (" Enter dish quantity :");
scanf ("%d",&d);
printf (" Price per dish size :RM%.2f\n\n\n",c);
return 0;
}
When I tried to change the format identifier in this to %c, it just stopped accepting input for that particular scanf.
printf ("Enter dish size (S/M/L):");
scanf ("%s",b);
I would like to attach images but it seems that I am not allowed to do so 'll leave two links:
Normal, using %s: and abnormal, using %c
I'm curious about why it doesn't work when I use %c
while %s
works? As all I enter there is just character. Please enlighten me.