I have an array of integers (binary[4]) and I want to put the contents into a string i.e
binary[0] = 1
binary[1] = 0
binary[2] = 1
binary[3] = 1
and i want a string
str = 1011
I thought of doing this
Code:
char str[50] //buffer size so never overflow
sprintf( str, "%d%d%d%d", binary[0],binary[1],binary[2],binary[3] );
But I dont always know the size of binary and anymore than 4 and i dont want to have to type it in How can I do it in a loop because
Code:
for i = 0;i<5;i++
{
sprintf( str, "%d", binary[i]);
}
just overwrites it