Compilation error due to table in C++

2019-09-17 05:38发布

问题:

I'm trying to create a chat programm for the TI-Nspire Calc via the serial port. So I installed the ndless SDK and nspireio lib to make the communication and it kind of works because there is an infite repetition of the message so I wrote this:

if(uart_ready()) {
    char input[100] = {0};
    uart_getsn(input,100);
    if(oldinput != input) {
            nio_puts(input);
            oldinput = input;
    }
 }

But when I compile it give me this error:

root@Kali-Linux:~/TINSPIRE/Ndless/ndless-sdk/samples/uart# make
nspire-g++ -Wall -W -marm -Os -c hello.cpp
hello.cpp: Dans la fonction « int main() »:
hello.cpp:61:14: error: affectation de tableau invalide
   oldinput = input;
              ^~~~~
Makefile:33 : la recette pour la cible « hello.o » a échouée
make: *** [hello.o] Erreur 1

What I'm doing wrong?

回答1:

If oldinput is also a char array,

replace oldinput=input with

strcpy(oldinput,input);


回答2:

You should declare oldinput:

char oldinput[100] = {0};

memcpy(oldinput, input, sizeof(char) * 100);