2024-05-29 02:23 PM - edited 2024-05-29 02:24 PM
Hello i have an Arduino project. I need create an array of words from sentence:
char sText[] = "This is a long text.";
int x = 0;
String arr[5];
//split by space
char *token = strtok(sText, " ");
while (token != NULL) {
arr[x] = token;
x++;
token = strtok(NULL, " ");
}
//new sentence > "This text"
char sNewText[] = arr[0] + " " + arr[4];
How can I do it similar in stm32CubeIde?
2024-05-29 02:37 PM
Standard part of string.h surely?
Would probably use strsep() as it's thread safe
2024-05-29 02:55 PM - edited 2024-05-29 02:57 PM
thx for your quickly reply, ofcourse i use string.h
#include <string.h>
but I have plenty of errors:
String or string
strsep or strtok does similar errors
gui/src/encrypt_screen/EncryptView.cpp: In member function 'virtual void EncryptView::DoEncrypt()':
gui/src/encrypt_screen/EncryptView.cpp:109:2: error: 'String' was not declared in this scope
String arr[5]; //string arr[5];
^~~~~~
gui/src/encrypt_screen/EncryptView.cpp:109:2: note: suggested alternative: 'stdin'
String arr[5];
^~~~~~
stdin
gui/src/encrypt_screen/EncryptView.cpp:111:16: error: 'strsep' was not declared in this scope
char *token = strsep(sText, " ");
^~~~~~
gui/src/encrypt_screen/EncryptView.cpp:111:16: note: suggested alternative: 'strset'
char *token = strsep(sText, " ");
^~~~~~
strset
gui/src/encrypt_screen/EncryptView.cpp:113:6: error: 'arr' was not declared in this scope
arr[x] = token;
^~~
gui/src/encrypt_screen/EncryptView.cpp:113:6: note: suggested alternative: 'VarOr'
arr[x] = token;
^~~
VarOr
generated/simulator/gcc/Makefile:196: recipe for target 'build/MINGW32_NT-6.2/gui/src/encrypt_screen/EncryptView.o' failed
make[2]: *** [build/MINGW32_NT-6.2/gui/src/encrypt_screen/EncryptView.o] Error 1
make[1]: *** [generate_assets] Error 2
generated/simulator/gcc/Makefile:155: recipe for target 'generate_assets' failed
make: *** [all] Error 2
simulator/gcc/Makefile:32: recipe for target 'all' failed
Failed
2024-05-29 04:04 PM
Yeah, the mix-n-match of C/C++ will be fun.
https://www.programiz.com/cpp-programming/library-function/cstring/strtok