Advertisement
Yonka2019

main.c

Jun 18th, 2021
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.98 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. /*********************************
  3. * Class: MAGSHIMIM C2            *
  4. * Week: 11                       *
  5. * Name: Final Project            *
  6. * Credits: Yonka                 *
  7. **********************************/
  8.  
  9. #include <stdio.h>
  10. #include <stdbool.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #define _CRTDBG_MAP_ALLOC
  14. #include <crtdbg.h>
  15. #include "linkedList.h"
  16.  
  17. #define STR_LEN 50
  18.  
  19. #define EXIT 0
  20. #define ADD 1
  21. #define REMOVE 2
  22. #define CHANGE_INDEX 3
  23. #define CHANGE_DURATION 4
  24. #define CHANGE_ALL_DURATIONS 5
  25. #define FRAME_LIST 6
  26. #define PLAY 7
  27. #define SAVE 8
  28.  
  29. #define FALSE 0
  30. #define TRUE !FALSE
  31.  
  32. void changeIndex(FrameNode** head, char* name, int index);
  33. void changeDuration(FrameNode** head, char* name, int duration);
  34. void changeAllDurations(FrameNode** head, int duration);
  35. void freeMemory(FrameNode* head);
  36. void insertAtEnd(FrameNode** head, Frame* newNode);
  37. void printList(FrameNode* head);
  38. void loadProject(char* path);
  39. void askLoadProject();
  40. void myFgets(char str[], int n);
  41. int selectMenu();
  42. int getLength(FrameNode* head);
  43. bool frameExist(FrameNode* head, char* name);
  44. bool removeFrame(FrameNode** head, char* name);
  45. Frame* initFrame(FrameNode* head);
  46. FrameNode* createFrameNode();
  47. Frame* createFrame(char* path, int duration, char* name);
  48.  
  49. int main(void)
  50. {
  51.     int choice = 1;
  52.  
  53.     FrameNode* head = NULL;
  54.     Frame* newFrame = NULL;
  55.  
  56.     //askLoadProject();
  57.  
  58.     while (choice != EXIT)
  59.     {
  60.         choice = selectMenu();
  61.         switch (choice)
  62.         {
  63.             case ADD:
  64.                 newFrame = initFrame(head);
  65.                 insertAtEnd(&head, newFrame);
  66.                 break;
  67.             case REMOVE:
  68.             {
  69.                 char name[STR_LEN] = { 0 };
  70.  
  71.                 printf("Enter the name of the frame you wish to erase\n");
  72.                 myFgets(name, STR_LEN);
  73.  
  74.                 if (!removeFrame(&head, name))
  75.                 {
  76.                     printf("This frame doesn't exist!\n");
  77.                 }
  78.                 break;
  79.             }
  80.             case CHANGE_INDEX:
  81.             {
  82.                 char name[STR_LEN] = { 0 };
  83.                 int newIndex = 0;
  84.  
  85.                 printf("Enter the name of the frame\n");
  86.                 myFgets(name, STR_LEN);
  87.  
  88.                 printf("Enter the new index in the movie you wish to place the frame\n");
  89.                 scanf("%d", &newIndex);
  90.                 getchar();
  91.  
  92.                 changeIndex(&head, name, newIndex);
  93.                 break;
  94.             }
  95.             case CHANGE_DURATION:
  96.             {
  97.                 char name[STR_LEN] = { 0 };
  98.                 int newDuration = 0;
  99.  
  100.                 printf("Enter the name of the frame you wish to change his duration\n");
  101.                 myFgets(name, STR_LEN);
  102.  
  103.                 printf("Enter the new duration to this frame\n");
  104.                 scanf("%d", &newDuration);
  105.                 getchar();
  106.  
  107.                 changeDuration(&head, name, newDuration);
  108.  
  109.                 break;
  110.             }
  111.             case CHANGE_ALL_DURATIONS:
  112.             {
  113.                 int newDuration = 0;
  114.  
  115.                 printf("Enter the new duration to all frames\n");
  116.                 scanf("%d", &newDuration);
  117.                 getchar();
  118.  
  119.                 changeAllDurations(&head, newDuration);
  120.                 break;
  121.             }
  122.             case PLAY:
  123.                 //play()
  124.                 break;
  125.             case EXIT:
  126.                 freeMemory(head);
  127.                 printf("\nBye!\n");
  128.                 printf("Leaks: %d", _CrtDumpMemoryLeaks());
  129.                 break;
  130.             case FRAME_LIST:
  131.                 printList(head);
  132.                 break;
  133.             default:
  134.                 printf("Invalid Input, please try again\n");
  135.                 break;
  136.         }
  137.     }
  138.     getchar();
  139.     return 0;
  140. }
  141. int selectMenu()
  142. {
  143.     int choice = 0;
  144.  
  145.     printf("What would you like to do?\n"
  146.         "   [0] Exit\n"
  147.         "   [1] Add new Frame\n"
  148.         "   [2] Remove a Frame\n"
  149.         "   [3] Change frame index\n"
  150.         "   [4] Change frame duration\n"
  151.         "   [5] Change duration of all frames\n"
  152.         "   [6] List frames\n"
  153.         "   [7] Play movie!\n"
  154.         "   [8] Save project\n");
  155.     scanf("%d", &choice);
  156.     getchar();
  157.  
  158.     return choice;
  159. }
  160. void askLoadProject()
  161. {
  162.     int loadExistingProject = 0;
  163.  
  164.     printf("Welcome to Magshimim Movie Maker! what would you like to do?\n"
  165.         "   [0] Create a new project\n"
  166.         "   [1] Load existing project \n");
  167.     scanf("%d", &loadExistingProject);
  168.     getchar();
  169.  
  170.     if (loadExistingProject)
  171.     {
  172.         char path[STR_LEN] = { 0 };
  173.  
  174.         printf("Enter the path of the project <including project name>:\n");
  175.         myFgets(path, STR_LEN);
  176.         loadProject(path);
  177.     }
  178. }
  179. void loadProject(char* path)
  180. {
  181.     //load project
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement