How can I add multiple ints to a character array, then pull them out?
I am trying to place 3 integers(byte size is 4) into a character string
byte by byte using c. I then need to "extract" the integers out of the
character array so I can do integer operations on them. I have looked
around and could not find any solutions to this. I think this will require
some type of pointer use or shifting, but I cannot figure out how to write
it.
char str[12]="";
int a;
int b;
int c;
int x;
int y;
int z;
a=5;
b=7;
c=12;
I know that an int is 4 bytes. I would like to make it so the str char
array has the following data in it.
str = |a1|a2|a3|a4|b1|b2|b3|b4|c1|c2|c3|c4|
*I do not want it like this. str=|'5'|'7'|'12'|
I then need to "extract" the integers out of the character array.
x=str[0-3]; //extracting a
y=str[4-7]; //extracting b
z=str[8-11]; //extracting c
After this, I should be able to write x=y+z and x will be equal to 19.