I am trying to send some data from an micro controller to the PC. The data is 10 bit ADC conversions(e.g numbers from 0-1023) from different ports. I have saved this number as an integer and I would now want to transform this to an ascii string using itoa or a similar function. My problem is that I am having some trouble to find the documentation for the itoa function. for instance if i receive the number "1011" from the AD conversion. then I can call itoa as follows
itoa(AD_value,ADC_string,10); //itoa("value", char* destination, base)
and the result in ADC_string would be "1 0 1 1 '\0'" e.g 1011; But say that I instead receive the number 5 from the AD conversion, then the result would be "5 '\0' Null Null Null" instead(If I have understood how itoa works correctly). I would have liked the result to be "0 0 0 5 '\0'" instead. The reason for this is that I would like to place the result in a large string at different places. e.g
large_string[0]=id_PC;
large_string[1]=ADC_string[0]; //start of ascii string of the latest value from a port
large_string[2]=ADC_string[1];
large_string[3]=ADC_string[2];
large_string[4]=ADC_string[3];
and for another port (there exist other stuff in large_string at index 5 & 6)
large_string[7]=ADC_string[0]; //start of ascii string of the latest value from another port
large_string[8]=ADC_string[1];
large_string[9]=ADC_string[2];
large_string[10]=ADC_string[3];
I would in other words like to have following in large_string according to my example above.
large_string[0]=id_PC
// an AD conversion from the first port is stored at index 1-4
large_string[1]='1'
large_string[2]='0'
large_string[3]='1'
large_string[4]='1'
large_string[5]=' '
large_string[6]=' '
// a new AD conversation from the second port is stored at index 7-10
large_string[7]='0'
large_string[8]='0'
large_string[9]='0'
large_string[10]='5'
large_string[11]='\0'
(I do AD conversion at one port at the time, which is the reason that I can reuse ADC_string). large_string shall later be sent to a PC which is the reason why I want to avoid unintended string terminators.
Do anyone have an idea on how this can be implemented in a nice manner? I am thankful for any suggestions!