This commit is contained in:
mpabi 2024-05-24 10:20:44 +00:00
parent 24ea59f8bb
commit 40373170ac
1 changed files with 40 additions and 41 deletions

View File

@ -7,7 +7,6 @@ int strlen(char *s) {
return p - s; return p - s;
} }
void strcpy(char *s, char *t) void strcpy(char *s, char *t)
{ {
while (*s++ = *t++); while (*s++ = *t++);
@ -38,7 +37,7 @@ char *alloc(int n)
#define LEN (8+2)*10 #define LEN (8+2)*10
struct model { struct model {
char * str; char * ptr;
uint32_t len ; uint32_t len ;
}; };
@ -73,7 +72,6 @@ char *simple_strtok(char *str, const char *delims) {
// " .,mpabi" // " .,mpabi"
// ^ // ^
// Pomiń początkowe delimitery // Pomiń początkowe delimitery
while (*static_str && is_delim(*static_str, delims)) { while (*static_str && is_delim(*static_str, delims)) {
static_str++; static_str++;
@ -87,6 +85,8 @@ char *simple_strtok(char *str, const char *delims) {
// Zapisz początek tokenu // Zapisz początek tokenu
char *token_start = static_str; char *token_start = static_str;
//,. mpabi pabi
// Znajdź koniec tokenu // Znajdź koniec tokenu
while (*static_str && !is_delim(*static_str, delims)) { while (*static_str && !is_delim(*static_str, delims)) {
static_str++; static_str++;
@ -102,62 +102,61 @@ char *simple_strtok(char *str, const char *delims) {
return token_start; return token_start;
} }
char buf[100];
char buf[1000];
struct model * p = (struct model *) buf; //p[1] struct model * p = (struct model *) buf; //p[1]
//
////func alg ////func alg
//in: ptr to date //in: ptr to date
//return: count of words //return: count of words
int alg (const char * ptr) { int alg (char * ptr) {
char bufer[ALLOCSIZE];
strcpy(bufer, (char *)ptr);
const char *delims = " ,.!?:;\n\t"; 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[pos].ptr = token;
p[count].len = strlen(token); //p[pos].len = strlen(token);
p[pos].len = pos;
token = simple_strtok((char *)NULL, delims); ++pos;
count++;
} }
return count; return pos;
} }
/*
struct model {
char * str;
uint32_t len ;
} tab [10] ;
*/
int main() { 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); alg(str);
asm ("nop"); asm ("nop");
return 1; 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