Hi everybody,
I have the need to pass a char array to a inline C code:
B4X:
'B4R code
FindString("DR3=")
public Sub FindString(src() As Byte)
RunNative("findstring", src)
Return
End Sub
//B4R C
#if C
B4R::Object* findstring(B4R::Object* o) {
char *testx= (char *)B4R::Object::toPointer(o);
Serial.println(testx);
}
#end if
It prints a single char(+). It's a long time I don't use C and C++ and I cannot see what I'm missing...
Private Sub AppStart
Serial1.Initialize(115200)
Log("appstart")
Dim bb() As Byte = "abc"
RunNative("PassBytes", bb)
End Sub
#if C
void PassBytes(B4R::Object* o) {
B4R::Array* b = (B4R::Array*)B4R::Object::toPointer(o);
char* c = (char*)b->data;
::Serial.println(c);
}
#end if
BTW, if you are searching in strings or arrays of bytes then you can use ByteConverter from rRandomAccessFile library.
You can use ByteConverter to search in arrays of bytes. You will need to read the data to an array and then search in it. You should of course only load small parts of the data each time.