Hello, I'm Styvak and I work on a project about an autopilot for boat at school and I've a problem to convert int variables to char and make a char array with these values. I have got 3 int from the GPS to get the date and I want to convert them in a char array like this "XX/XX/XX :" I've tried severals solutions like the itoa function or use this syntax " (char*)myVariable " but when I try to compile it I've got an error when I added all the char like this : " date = day + '/' + month + '/' + year + ' :'; " The error is : "error: invalid operands of types 'char*' and 'char*' to binary 'operator+'" Thank you in advance, Cordially, Styvak
when I added all the char like this : " date = day + '/' + month + '/' + year + ' :'; "
That's because you are tying to concatenate a a char array with the + which is not allowed in char arrays.The + will only work on String objects. Read this http://arduino.cc/en/Reference/StringObject
I had convert into a string :
itoa(day, jour, 10); itoa(month, mois, 10); itoa(year, annee, 10); date = jour + "/" + mois + "/" + annee + " :";
But I've already got an error : " error: invalid operands of types 'char ' and 'const char ' to binary 'operator+' " and it is possible to convert string to char ?
Declare a char array big enough to hold the string, including the null terminator. Use snprintf() to write the values to the char array.