From 40373170ac269f6d699a7a5f8d32a1bb2a9d350b Mon Sep 17 00:00:00 2001 From: mpabi Date: Fri, 24 May 2024 10:20:44 +0000 Subject: [PATCH] :( --- cpp/_rvmain.cpp | 81 ++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/cpp/_rvmain.cpp b/cpp/_rvmain.cpp index ebf205d..e1c570a 100644 --- a/cpp/_rvmain.cpp +++ b/cpp/_rvmain.cpp @@ -7,7 +7,6 @@ int strlen(char *s) { return p - s; } - void strcpy(char *s, char *t) { while (*s++ = *t++); @@ -38,7 +37,7 @@ char *alloc(int n) #define LEN (8+2)*10 struct model { - char * str; + char * ptr; uint32_t len ; }; @@ -73,7 +72,6 @@ char *simple_strtok(char *str, const char *delims) { // " .,mpabi" // ^ - // Pomiń początkowe delimitery while (*static_str && is_delim(*static_str, delims)) { static_str++; @@ -87,6 +85,8 @@ char *simple_strtok(char *str, const char *delims) { // Zapisz początek tokenu char *token_start = static_str; + + //,. mpabi pabi // Znajdź koniec tokenu while (*static_str && !is_delim(*static_str, delims)) { static_str++; @@ -102,62 +102,61 @@ char *simple_strtok(char *str, const char *delims) { return token_start; } -char buf[100]; + +char buf[1000]; struct model * p = (struct model *) buf; //p[1] + // + + ////func alg //in: ptr to date //return: count of words -int alg (const char * ptr) { - - char bufer[ALLOCSIZE]; - strcpy(bufer, (char *)ptr); +int alg (char * ptr) { const char *delims = " ,.!?:;\n\t"; - int8_t count = 0; + int pos = 0; - char *token = simple_strtok(bufer, delims); + while (char *token = simple_strtok(ptr, delims)) { - while (token != (char *)NULL) { + if (token == (char *)NULL) + break; - p[count].str = token; - p[count].len = strlen(token); - - token = simple_strtok((char *)NULL, delims); - count++; - } + p[pos].ptr = token; + //p[pos].len = strlen(token); + p[pos].len = pos; + ++pos; + } - return count; + return pos; } +/* +struct model { + char * str; + uint32_t len ; +} tab [10] ; +*/ + int main() { +// Seccess is often +// ^ + char *str = " Success is often defined as the ability to reach your goals in life, whatever those goals may be. In some ways, a better word for success might be attainment, accomplishment, or progress. It is not necessarily a destination but a journey that helps develop the skills and resources you need to thrive."; - char *str = "If wantered relation no surprise of all"; +/* + struct model *ptr = (struct model *) alloc(LEN); + if (ptr != (struct model *)NULL) { + ptr->str = alloc(strlen((char *)str) + 1); + if (ptr->str != (char *)NULL) { + strcpy (ptr->str, (char *)str); + ptr->len = strlen(ptr->str); + int8_t count = alg(ptr->str); + } + } + */ alg(str); asm ("nop"); return 1; } - -// wynik tego kodu: -// p[0].str = If -// p[0].len = 2 - -// p[1].str = wantered -// p[1].len = 8 - -// p[2].str = relation -// p[2].len = 8 - -// p[3].str = no -// p[3].len = 2 - -// p[4].str = surprise -// p[4].len = 8 - -// p[5].str = of -// p[5].len = 2 - -// p[6].str = all -// p[6].len = 3