Advertisement
Guest User

ivan

a guest
Dec 6th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <stdlib.h>
  6.  
  7. #define strSize 1000 //  число строк/столбцов
  8.  
  9.  
  10. //  структура карты
  11. typedef struct
  12. {
  13.     int rows;
  14.     int cols;
  15.     unsigned char *cells;
  16. } Map;
  17.  
  18. //  является ли символ числом
  19. bool isCharNum(char *argument)
  20. {
  21.     int len = strlen(argument);
  22.     bool result = true;
  23.     for (int i = 0; i < len; i++)
  24.     {
  25.         if (!isdigit(argument[i]))
  26.         {
  27.             result = false;
  28.         }
  29.     }
  30.     return result;
  31. }
  32.  
  33. //  определение границы
  34. /*bool isborder (Map *map, int r, int c, int border)
  35. {
  36.    
  37. }*/
  38.  
  39. //  определение стартовой границы
  40. /*int startBorder (Map *map, int r, int c, int leftright)
  41. {
  42.  
  43. }*/
  44.  
  45. //  сколько слов в строке, без пробелов
  46. /*char *wordsInStr(char *str)
  47. {
  48.     int i;
  49.     int space = 0;
  50.     int words = 0;
  51.     while (str[i] != '\n')
  52.     {
  53.        
  54.     }
  55. }*/
  56.  
  57. bool fileTxt(char *fileName)
  58. {
  59.     if ((fileName[strlen(fileName) - 4] == '.') && (fileName[strlen(fileName) - 3] == 't') && (fileName[strlen(fileName) - 2] == 'x') && (fileName[strlen(fileName) - 1] == 't'))   //strstr(fileName, ".txt") != NULL)
  60.     {
  61.         printf("%s\n", "File txt");
  62.         return true;
  63.     }
  64.     else
  65.     {
  66.         printf("%s\n", "File not txt");
  67.         return false;
  68.     }
  69. }
  70.  
  71. //  проверка карты
  72. bool *mapTest(char *fileName)
  73. {
  74.     //char *num1;
  75.     //char *num2;
  76.     //int rows, cols;
  77.     FILE *fp;
  78.     fp = fopen(fileName, "r");
  79.     if (fp == NULL)
  80.     {
  81.         fprintf(stderr, "%s\n", "Can't open file");
  82.         return false;
  83.     }
  84.     else
  85.     {
  86.         char *str = "";
  87.         printf("%s\n", "lox");
  88.         fgets(str, strSize, fp); //fscanf(fp, "%s", str);
  89.         //fscanf(fp, "%s", str);
  90.         printf("%s\n", str);
  91.         /*if (isCharNum(num1) && isCharNum(num2))
  92.         {
  93.            
  94.         }
  95.         else
  96.         {
  97.             fprintf(stderr, "%s\n", "Invalid file");
  98.         }*/
  99.        
  100.     }
  101.     printf("%s\n", "lox");
  102.     fclose(fp);
  103.    
  104.     return 0;
  105. }
  106.  
  107. /*void mapInicializace()
  108. {
  109.     char *num1, num2;
  110.     int rows, cols;
  111.     FILE *fp;
  112.     fp = fopen("bludiste.txt", "r");
  113.     if (fp == NULL)
  114.     {
  115.         fprintf(stderr, "%s\n", "Error: file neobsahuje informace");
  116.         return -1;
  117.     }
  118.     else
  119.     {
  120.         char *result = fgetc(str, sizeof(str), fp);
  121.         if (isCharNum(num1) && isCharNum(num2))
  122.         {
  123.            
  124.         }
  125.         else
  126.         {
  127.             fprintf(stderr, "%s\n", "Invalid file");
  128.         }
  129.        
  130.     }
  131.    
  132.     return 0;    
  133. }*/
  134.  
  135. /*void mapScitovani()
  136. {
  137.    
  138.  
  139.    
  140. }
  141.  
  142. void mapClearing()
  143. {
  144.  
  145. }*/
  146.  
  147. int main()//int main (int argc, char *argv[])
  148. {
  149.     int argc = 3;
  150.     char *argv1 = "--test";
  151.     char *argv2 = "bludiste.txt";
  152.     if (argc == 2 && (strcmp(argv1, "--help") == 0))
  153.     {
  154.         printf("Napoveda!\nZadejte vstup, cislo radku a cislo sloupci!\nSpecialni komandy:\n --help - vypisuje napovedu\n --test nazev_souboru.txt - zkontroluje, ze soubor dany druhym argumentem programu obsahuje radnou definici mapy bludiste\n --rpath R C nazev_souboru.txt - hleda pruchod bludistem, zadanym z souboru txt, na vstupu na rádku R a sloupci C. Pruchod hleda pomoci pravidla prave ruky (prava ruka vzdy na zdi)\n --lpath R C nazev_souboru.txt - hleda pruchod bludistem, zadanym z souboru txt, na vstupu na rádku R a sloupci C. Pruchod hleda pomoci pravidla leve ruky (leva ruka vzdy na zdi)\n --shortest R C nazev_souboru.txt - hleda nejkratsi cestu z bludiste, zadanym z souboru txt, pri vstupu na radku R a sloupci C\n");
  155.         return 0;
  156.     }
  157.        
  158.     else if (argc == 3 && strcmp(argv1, "--test") == 0 && fileTxt(argv2))
  159.     {
  160.         if (mapTest(argv2))
  161.         {
  162.             printf("Valid\n");
  163.         }
  164.        // else
  165.         {
  166.             printf("Invalid\n");
  167.         }
  168.        
  169.            //    тестирование файла
  170.     }
  171.        
  172.     //  основной цикл
  173.     /*else if (argc == 5)
  174.     {
  175.         //int leftright;
  176.         //  правило правой руки
  177.         if (isCharNum(argv[2]) && isCharNum(argv[3]))
  178.         {
  179.             int startRows = atoi(argv[2]);
  180.             int startCols = atoi(argv[3]);
  181.             if ((strcmp(argv[1], "--rpath") == 0) && (argv2 < 0 && argv2 <= rows) && (argv3 > 0 && argv3 < cols) && (strcmp(argv[4], "bludiste.txt") == 0))
  182.             {
  183.                 //leftright = 0;
  184.                 printf("Ty pidor");
  185.                 return 0;
  186.             }
  187.             //  правило левой руки
  188.             else if ((strcmp(argv[1], "--lpath") == 0) && (argv2 > 0 && argv2 <= rows) && (argv3 > 0 && argv3< cols) && (strcmp(argv[4], "bludiste.txt") == 0))
  189.             {
  190.                 //leftright = 1;
  191.                 return 0;
  192.             }
  193.             //  самый короткий путь
  194.             else if((strcmp(argv[1], "--shortest") == 0) && (argv2 > 0 && argv2 <= rows) && (argv3 > 0 && argv3 < cols) && (strcmp(argv[4], "bludiste.txt") == 0))
  195.             {
  196.                 //leftright =1;
  197.                 return 0;
  198.             }
  199.             else
  200.             {
  201.             fprintf(stderr,"%s\n", "Error: chybna komanda\nPro napovedu napiste --help\n");
  202.             return -1;            
  203.             }
  204.         }
  205.         else
  206.         {
  207.             fprintf(stderr,"%s\n", "Error: chybna komanda\nPro napovedu napiste --help\n");
  208.             return -1;            
  209.         }  
  210.     }
  211.     else
  212.     {
  213.         fprintf(stderr,"%s\n", "Error: chybna komanda\nPro napovedu napiste --help\n");
  214.         return -1;
  215.     }*/
  216.     return 0;
  217. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement