Advertisement
Guest User

order c program

a guest
May 26th, 2012
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.49 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int i = 0;
  6.  
  7. typedef struct
  8. {
  9.  
  10.     char *entree[80];
  11.     char *drink[80];
  12.     char *dessert[80];
  13.  
  14. } order;
  15.  
  16. void print_commands()
  17. {
  18.     printf("e: entree\n");
  19.     printf("d: drink\n");
  20.     printf("t: dessert\n");
  21.     printf("o: print complete order\n");
  22.     printf("c: print list of commands\n");
  23.     printf("w: write to text file\n");
  24.     printf("x: exit\n");
  25. }
  26.  
  27.  
  28. void ask_order()
  29. {
  30.  
  31.  
  32.     char choice;
  33.     order o;
  34.     FILE *orderfile = NULL;
  35.     orderfile = fopen("order.txt", "w");
  36.  
  37.     printf("Welcome\nWhat Would you like to order?:\n");
  38.     printf("Commands:\n\n");
  39.     print_commands();
  40.     while (i == 0)
  41.     {
  42.         printf("\nENTER_OPTION>");
  43.         scanf("%c", &choice);
  44.         switch (choice)
  45.         {
  46.  
  47.         case 'e':
  48.  
  49.             printf("Enter your entree: ");
  50.             scanf("%s", o.entree);
  51.             break;
  52.  
  53.         case 'd':
  54.             printf("Enter your drink: ");
  55.             scanf("%s", o.drink);
  56.             break;
  57.  
  58.         case 't':
  59.             printf("Enter a dessert: ");
  60.             scanf("%s", o.dessert);
  61.             break;
  62.  
  63.         case 'o':
  64.             printf("Entree: %s\n", o.entree);
  65.             printf("Drink: %s\n", o.drink);
  66.             printf("Dessert: %s\n", o.dessert);
  67.             break;
  68.  
  69.         case 'c':
  70.             print_commands();
  71.             break;
  72.  
  73.         case 'w':
  74.             printf("Saving to File...\n");
  75.             /* This isnt Working, it segfaults... */
  76.             fprintf(orderfile, "Entree: %s\nDrink: %s\nDessert: %s\n",
  77.                     o.entree, o.drink, o.dessert);
  78.             fclose(orderfile);
  79.             break;
  80.  
  81.         case 'x':
  82.  
  83.             i += 1;
  84.             break;
  85.  
  86.  
  87.         }
  88.     }
  89. }
  90.  
  91.  
  92. int main()
  93. {
  94.     ask_order();
  95.     return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement