Advertisement
rabin9596

Code4_1001733634

Apr 5th, 2020
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.50 KB | None | 0 0
  1. // Rabindra Yadav 1001733634
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include "DrawTool.h"
  6.  
  7. int main (void)
  8. {
  9.     char array [Max_Size][Max_Size] = {};
  10.     int test = 1;
  11.     int user_size, i, token2, token3, token4, horizontal_limit, vertical_limit;
  12.     char input[Max_Size] = {};
  13.     char *location = NULL, *token1_Ptr = NULL, *token2_Ptr = NULL, *token3_Ptr = NULL, *token4_Ptr = NULL, *token5_Ptr = NULL;
  14.     char token1 = '0', token5 = '0', try;
  15.     initializeMap(array, &user_size);
  16.     printInstructions();
  17.     while (input[0] != 'q' && input[0] != 'Q')
  18.     {
  19.         printf("\n");
  20.         printMap(array, &user_size);
  21.         printf("Enter draw command (enter Q to quit) ");
  22.         location = fgets(input, Max_Size - 1, stdin);
  23.         if (input[0] != 'q' && input[0] != 'Q')
  24.         {
  25.             token1_Ptr = strtok(input, "(,)");
  26.             token2_Ptr = strtok(NULL, "(,)");
  27.             token3_Ptr = strtok(NULL, "(,)");
  28.             token4_Ptr = strtok(NULL, "(,)");
  29.             token5_Ptr = strtok(NULL, "(,)");
  30.             token1 = *token1_Ptr, token5 = *token5_Ptr;
  31.             token2 = atoi(token2_Ptr);
  32.             token3 = atoi(token3_Ptr);
  33.             token4 = atoi(token4_Ptr); 
  34.             if (token5 == '0' || token5 == '\0')
  35.             {
  36.                 token5 = 'X';
  37.             }
  38.             if (token2 < 0 || token2 >= user_size)
  39.             {
  40.                 printf("That draw command is out of range\n\n");
  41.                 test = 0;
  42.             }
  43.             else if (token3 < 0 || token3 >= user_size)
  44.             {
  45.                 printf("That draw command is out of range\n\n");
  46.                 test = 0;
  47.             }
  48.             else if (token1 != 'P' && token1 != 'p')
  49.             {
  50.                 if (token4 < 0 || token4 >= user_size)
  51.                 {
  52.                     printf("That draw command is out of range\n\n");
  53.                     test = 0;
  54.                 }
  55.                 else if (token1 == 'H' || token1 == 'h')
  56.                 {
  57.                     horizontal_limit = user_size - token3;
  58.                     if (token4 > horizontal_limit)
  59.                     {
  60.                         printf("That draw command is out of range\n\n");
  61.                         test = 0;
  62.                     }
  63.                 }
  64.                 else if (token1 == 'V' || token1 == 'v')
  65.                 {
  66.                     vertical_limit = user_size - token2;
  67.                     if (token4 > vertical_limit)
  68.                     {
  69.                         printf("That draw command is out of range\n\n");
  70.                         test = 0;
  71.                     }
  72.                 }
  73.             }
  74.             if (test == 1)
  75.             {
  76.                 if (token1 == 'P' || token1 == 'p')
  77.                 {
  78.                     *(*(array + token2) + token3) = token5;    
  79.                 }
  80.                 else if (token1 == 'V' || token1 == 'v')
  81.                 {
  82.                     drawLines(array, token2, token3, token1, token4, token5);
  83.                 }
  84.                 else if (token1 == 'H' || token1 == 'h')
  85.                 {
  86.                     drawLines(array, token2, token3, token1, token4, token5);
  87.                 }
  88.                 else
  89.                 {
  90.                     printf("That draw command is unkown");
  91.                 }
  92.             }
  93.         }
  94.     }
  95.     printf("\n\n");
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement