Go Down

Topic: Convert Array of chars to integer except the first position (Read 673 times) previous topic - next topic

blastboot

Hello, i'm trying to convert a message received with VirtualWire library that starts with an 'R' to an integer, but at this time i couldn't find an explanation to this.
The message received is like "R016" and it is stored in a array like message[3] and i want to convert message to integer (like atoi function does) but except the letter 'R'.

Can you please give me some help?? THANKS in advance!!

Delta_G

Use atoi but pass it a pointer to the second element in the array instead of the first.

Arrch


Hello, i'm trying to convert a message received with VirtualWire library that starts with an 'R' to an integer, but at this time i couldn't find an explanation to this.
The message received is like "R016" and it is stored in a array like message[3] and i want to convert message to integer (like atoi function does) but except the letter 'R'.

Can you please give me some help?? THANKS in advance!!


How can four letters and a null terminating character be stored in a 3 byte array?

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

majenko

I'll second that motion ;)

It should be message[5], for 4 characters plus terminating null.

And you would use

Code: [Select]

int value = atoi(message+1);


Or, more explicitly:
Code: [Select]

int value = atoi(&message[1]);
Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Go Up