I tried to do it myself, but failed (I am tempted to do it again for training, but I just need it as an example). Essentially, I want to represent a binary number, but of course with the closest byte to 0, so I found a function on a different issue here:
char * string_pad(char * string, size_t padlen, char * pad) {
size_t lenstring = strlen(string);
size_t lenpad = strlen(pad);
char * padded = (char*)malloc(lenstring + lenpad + 1);
strncpy(padded, string, lenstring);
padded += lenstring;
for(padlen += 1; padlen > 0; padlen--, padded += lenpad)
strncpy(padded, pad, lenpad);
*padded = '\0';
return padded;
}
I call it this way:
printf("Test: %s\n", string_pad(dec2bin(~myInt), 32, "0"));
Unfortunately, he prints "Test:", but nothing more. Mine dec2binreturns a simple char pointer if you need to know.
What seems to make him do nothing?
Why does this function accept a char * panel, not a char panel, so I can just put it with "0", will "0" work or will it add a null terminator, twisting it or something like that?
. - ( ), ? .
chararray, , , , .