B4R Question Passing a char array to a inline C code

tigrot

Well-Known Member
Licensed User
Longtime User
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...

Best regards
Mauro Zanin
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
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.
 
Upvote 0
Top