Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int i = 0;
- typedef struct
- {
- char *entree[80];
- char *drink[80];
- char *dessert[80];
- } order;
- void print_commands()
- {
- printf("e: entree\n");
- printf("d: drink\n");
- printf("t: dessert\n");
- printf("o: print complete order\n");
- printf("c: print list of commands\n");
- printf("w: write to text file\n");
- printf("x: exit\n");
- }
- void ask_order()
- {
- char choice;
- order o;
- FILE *orderfile = NULL;
- orderfile = fopen("order.txt", "w");
- printf("Welcome\nWhat Would you like to order?:\n");
- printf("Commands:\n\n");
- print_commands();
- while (i == 0)
- {
- printf("\nENTER_OPTION>");
- scanf("%c", &choice);
- switch (choice)
- {
- case 'e':
- printf("Enter your entree: ");
- scanf("%s", o.entree);
- break;
- case 'd':
- printf("Enter your drink: ");
- scanf("%s", o.drink);
- break;
- case 't':
- printf("Enter a dessert: ");
- scanf("%s", o.dessert);
- break;
- case 'o':
- printf("Entree: %s\n", o.entree);
- printf("Drink: %s\n", o.drink);
- printf("Dessert: %s\n", o.dessert);
- break;
- case 'c':
- print_commands();
- break;
- case 'w':
- printf("Saving to File...\n");
- /* This isnt Working, it segfaults... */
- fprintf(orderfile, "Entree: %s\nDrink: %s\nDessert: %s\n",
- o.entree, o.drink, o.dessert);
- fclose(orderfile);
- break;
- case 'x':
- i += 1;
- break;
- }
- }
- }
- int main()
- {
- ask_order();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement