diff --git a/cpp/_rvmain.cpp b/cpp/_rvmain.cpp index 85e018a..d27d1ae 100644 --- a/cpp/_rvmain.cpp +++ b/cpp/_rvmain.cpp @@ -42,12 +42,71 @@ struct model { }; -//func alg +//alg +// prosta implementacji func. z bibl. std. strok przy uzyciu gpt3.5 +// + +#define NULL ((void*) 0) + +// +// Funkcja pomocnicza do sprawdzania, czy znak jest wśród delimiterów +bool is_delim(char c, const char *delims) { + while (*delims) { + if (c == *delims) { + return true; + } + delims++; + } + return false; +} + +// Najprostsza implementacja funkcji strtok +char *simple_strtok(char *str, const char *delims) { + static char *static_str = (char *) NULL; // Przechowuje wskaźnik do bieżącej pozycji w ciągu + + // Jeśli przekazano nowy ciąg, zaktualizuj static_str + if (str != NULL) { + static_str = str; + } + + // Jeśli static_str jest NULL, zwróć NULL + if (static_str == NULL) { + return (char *) NULL; + } + + // Pomiń początkowe delimitery + while (*static_str && is_delim(*static_str, delims)) { + static_str++; + } + + // Jeśli doszliśmy do końca ciągu, zwróć NULL + if (*static_str == '\0') { + return (char *) NULL; + } + + // Zapisz początek tokenu + char *token_start = static_str; + + // Znajdź koniec tokenu + while (*static_str && !is_delim(*static_str, delims)) { + static_str++; + } + + // Jeśli znaleziono delimitery, zamień je na '\0' i zaktualizuj static_str + if (*static_str) { + *static_str = '\0'; + static_str++; + } + + // Zwróć początek tokenu + return token_start; +} + +////func alg //in: ptr to date //return: count of words int alg (const char * ptr) { - return 1; }