Hi, why is the output some garbage value at the start of the first 2 bits? and then fine for the rest of the bits? I don't understand. Hope someone is able to help! Thanks.
That memset looks wrong. array is an int pointer, size 8 bytes (probably), but you want to write over all the int values in the array, which for 5 int values would be 40 bytes. memset(array, 0, sizeof(int) * k);
Also, I see no use of this anywhere: char* str;
so just remove it from the code to keep things simple and easier to read.