Yet, while I completely fail to see any purpose for creating such an array, here's what I came up with:
#include <exec/types.h>
#include <exec/memory.h>
#include <stdio.h>
#include <proto/exec.h>
int main (int argc, char **argv)
{
struct entry
{
UBYTE b[8];
} *array;
/* NOTE: Only the array of the last entry will actually take 9 bytes
* (since it has all bits set: 7 6 5 4 3 2 1 0. Thus only the last
* entry needs to have array of 9 bytes. Thus + 1.
*/
array = AllocMem(sizeof(*array) * 256 + 1, MEMF_ANY);
if (array)
{
int i;
for (i = 0; i < 256; i++)
{
int n, cnt = 0;
for (n = 8; n >= 0; n--)
{
if (i & (1 << n))
{
array[i].b[cnt++] = n + 1;
}
}
array[i].b[cnt] = 0;
}
/* TEST IT ! */
for (i = 0; i < 256; i++)
{
UBYTE *p = array[i].b;
printf("%u: ", i);
while (*p)
{
printf("%u ", *p++);
}
printf("\n");
}
FreeMem(array, sizeof(*array) * 256 + 1);
}
else
{
printf("No more memory !!\n");
}
return 0;
}
I took the liberty of changing the array type for simpler and more efficient code.