How to convert string array to string?

3

In a program for Arduino, I have an array of strings but it seems that the function where I am going to use this data only accepts string. How do I convert an array to a string?

File prog = SD.open("prog.bin");
String leiaS(void){

    return String(prog.read());


 }


   digitalWrite(leia(), inverte(leiaS()));


String inverte(String port){
     if(digitalRead(port)==HIGH)
      return LOW;
     else
      return HIGH;
  }

Error:

  

could not convert 'leiaS' from 'String (*) ()' to 'String'

I noticed that there was a missing parenthesis in the call of the leiaS function. After correcting and verifying the error appeared:

  

Can not convert 'String' to 'uint8_t {aka unsigned char}' for argument '2' to 'void digitalWrite (uint8_t, uint8_t)'

    
asked by anonymous 01.07.2015 / 19:21

2 answers

1

leiaS is set to function (of type String (*)(void) )

String leiaS(void) { /* ... */ }

The reference to leiaS in the digitalWrite line

digitalWrite(leia(), inverte(leiaS)));

As a parameter to the function inverte . I suppose the inverted function is defined as receiving a string: you can not pass a pointer to a function.

    
01.07.2015 / 20:05
1

You can do an iteration and read each character that read returns and adds it to an array of char.

char arrayLeitura[20];
int index=0; 
char charLeitura;

File prog = SD.open("prog.bin");
if (prog) {
    while (prog.available()) {
         charLeitura= prog.read();
         arrayLeitura[index++]=charLeitura;
    }
    prog.close();
}

I believe that later you can give

return String(arrayLeitura);
    
01.07.2015 / 19:49