Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdbool.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdlib.h>
- #define strSize 1000 // число строк/столбцов
- // структура карты
- typedef struct
- {
- int rows;
- int cols;
- unsigned char *cells;
- } Map;
- // является ли символ числом
- bool isCharNum(char *argument)
- {
- int len = strlen(argument);
- bool result = true;
- for (int i = 0; i < len; i++)
- {
- if (!isdigit(argument[i]))
- {
- result = false;
- }
- }
- return result;
- }
- // определение границы
- /*bool isborder (Map *map, int r, int c, int border)
- {
- }*/
- // определение стартовой границы
- /*int startBorder (Map *map, int r, int c, int leftright)
- {
- }*/
- // сколько слов в строке, без пробелов
- /*char *wordsInStr(char *str)
- {
- int i;
- int space = 0;
- int words = 0;
- while (str[i] != '\n')
- {
- }
- }*/
- bool fileTxt(char *fileName)
- {
- if ((fileName[strlen(fileName) - 4] == '.') && (fileName[strlen(fileName) - 3] == 't') && (fileName[strlen(fileName) - 2] == 'x') && (fileName[strlen(fileName) - 1] == 't')) //strstr(fileName, ".txt") != NULL)
- {
- printf("%s\n", "File txt");
- return true;
- }
- else
- {
- printf("%s\n", "File not txt");
- return false;
- }
- }
- // проверка карты
- bool *mapTest(char *fileName)
- {
- //char *num1;
- //char *num2;
- //int rows, cols;
- FILE *fp;
- fp = fopen(fileName, "r");
- if (fp == NULL)
- {
- fprintf(stderr, "%s\n", "Can't open file");
- return false;
- }
- else
- {
- char *str = "";
- printf("%s\n", "lox");
- fgets(str, strSize, fp); //fscanf(fp, "%s", str);
- //fscanf(fp, "%s", str);
- printf("%s\n", str);
- /*if (isCharNum(num1) && isCharNum(num2))
- {
- }
- else
- {
- fprintf(stderr, "%s\n", "Invalid file");
- }*/
- }
- printf("%s\n", "lox");
- fclose(fp);
- return 0;
- }
- /*void mapInicializace()
- {
- char *num1, num2;
- int rows, cols;
- FILE *fp;
- fp = fopen("bludiste.txt", "r");
- if (fp == NULL)
- {
- fprintf(stderr, "%s\n", "Error: file neobsahuje informace");
- return -1;
- }
- else
- {
- char *result = fgetc(str, sizeof(str), fp);
- if (isCharNum(num1) && isCharNum(num2))
- {
- }
- else
- {
- fprintf(stderr, "%s\n", "Invalid file");
- }
- }
- return 0;
- }*/
- /*void mapScitovani()
- {
- }
- void mapClearing()
- {
- }*/
- int main()//int main (int argc, char *argv[])
- {
- int argc = 3;
- char *argv1 = "--test";
- char *argv2 = "bludiste.txt";
- if (argc == 2 && (strcmp(argv1, "--help") == 0))
- {
- 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");
- return 0;
- }
- else if (argc == 3 && strcmp(argv1, "--test") == 0 && fileTxt(argv2))
- {
- if (mapTest(argv2))
- {
- printf("Valid\n");
- }
- // else
- {
- printf("Invalid\n");
- }
- // тестирование файла
- }
- // основной цикл
- /*else if (argc == 5)
- {
- //int leftright;
- // правило правой руки
- if (isCharNum(argv[2]) && isCharNum(argv[3]))
- {
- int startRows = atoi(argv[2]);
- int startCols = atoi(argv[3]);
- if ((strcmp(argv[1], "--rpath") == 0) && (argv2 < 0 && argv2 <= rows) && (argv3 > 0 && argv3 < cols) && (strcmp(argv[4], "bludiste.txt") == 0))
- {
- //leftright = 0;
- printf("Ty pidor");
- return 0;
- }
- // правило левой руки
- else if ((strcmp(argv[1], "--lpath") == 0) && (argv2 > 0 && argv2 <= rows) && (argv3 > 0 && argv3< cols) && (strcmp(argv[4], "bludiste.txt") == 0))
- {
- //leftright = 1;
- return 0;
- }
- // самый короткий путь
- else if((strcmp(argv[1], "--shortest") == 0) && (argv2 > 0 && argv2 <= rows) && (argv3 > 0 && argv3 < cols) && (strcmp(argv[4], "bludiste.txt") == 0))
- {
- //leftright =1;
- return 0;
- }
- else
- {
- fprintf(stderr,"%s\n", "Error: chybna komanda\nPro napovedu napiste --help\n");
- return -1;
- }
- }
- else
- {
- fprintf(stderr,"%s\n", "Error: chybna komanda\nPro napovedu napiste --help\n");
- return -1;
- }
- }
- else
- {
- fprintf(stderr,"%s\n", "Error: chybna komanda\nPro napovedu napiste --help\n");
- return -1;
- }*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement