This commit is contained in:
mpabi 2024-05-23 08:46:15 +00:00
parent 6836e07a9b
commit 8bf97ca90b
1 changed files with 28 additions and 11 deletions

View File

@ -65,15 +65,13 @@ char *simple_strtok(char *str, const char *delims) {
static char *static_str = (char *) NULL; // Przechowuje wskaźnik do bieżącej pozycji w ciągu 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 // Jeśli przekazano nowy ciąg, zaktualizuj static_str
if (str != NULL) { if (str == NULL) {
static_str = str; return (char *) NULL; // str nie wskazuje na zdanie !!!
}
// Jeśli static_str jest NULL, zwróć NULL
if (static_str == NULL) {
return (char *) NULL;
} }
static_str = str;
// " .,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++;
@ -102,6 +100,9 @@ char *simple_strtok(char *str, const char *delims) {
return token_start; return token_start;
} }
char buf[100];
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
@ -115,19 +116,32 @@ int alg (const char * ptr) {
int8_t count = 0; int8_t count = 0;
char *token = simple_strtok(bufer, delims); char *token = simple_strtok(bufer, delims);
while (token != (char *)NULL) {
while (token != (char *)NULL) {
p[count].str = token;
p[count].len = strlen(token);
token = simple_strtok((char *)NULL, delims);
count++; count++;
token = simple_strtok((char *)NULL, delims);
} }
return count; return count;
} }
/*
struct model {
char * str;
uint32_t len ;
} tab [10] ;
*/
int main() { int main() {
char *str = "If wantered relation no surprise of all"; char *str = "If wantered relation no surprise of all";
struct model *ptr = (struct model *) alloc(LEN); /*
struct model *ptr = (struct model *) alloc(LEN);
if (ptr != (struct model *)NULL) { if (ptr != (struct model *)NULL) {
ptr->str = alloc(strlen((char *)str) + 1); ptr->str = alloc(strlen((char *)str) + 1);
if (ptr->str != (char *)NULL) { if (ptr->str != (char *)NULL) {
@ -137,6 +151,9 @@ int main() {
int8_t count = alg(ptr->str); int8_t count = alg(ptr->str);
} }
} }
*/
alg(str);
asm ("nop");
return 1; return 1;
} }