
/* scanfEvilDemo.c   P. Conrad   9/12/05    

 demonstrates what happens when you mess up the % thingies

*/

#include <stdio.h>

int main(void)
{

  char kindOfFruit[12]; /* hold name of the fruit */
  int calories;  /* hold how many calories */

  printf("What kind of fruit would you like to eat? ");

  /* the scanf statment has two parts:
     1st part: format specifier: "%s" for example, means "string"
     2nd part: list of variables (in this case, only one) 
  */

  scanf("%s", &kindOfFruit); /* ampersand means "address of" */

  /* now ask how many calories are in 100g */
  
  printf("How many calories are in 1 cup of %s?", kindOfFruit );
  scanf("%d",&calories);

  /* \n prints a "new line" character. That's how you
     skip to the next line.  
     The %s is where we will put a string.
     The %d means "put an integer here".
     You list the things you want to print, after the format
     string, in the order of the format specifiers (e.g. %s %d)
     In the following line, the integer will be the result of
     multiplying calories times two. */


  /* In this evil version, I have deliberately switched the
     %s and the %d from where they should be. */

  printf("If you eat 2 cups of %s you'll eat %d calories\n",
	 kindOfFruit, calories * 2,calories,);

  return 0; /* to indicate success */
}
