We have a small assignment from college that requires us to perform some job X in C.
Part of that problem is to convert an unsigned long number, that is generated in the course of the program and hence without any way to predetrmine it, to a string. Naturally, i made use of snprintf
. I initialized an array (str[50]) that was generously sized to avoid any sort of buffer errors.
On submission, however, my professor said that my method of avoiding buffer errors was ineffecient.
My question now is, when i create an char array to hold the unsigned long value, what size do i make it as? Is there some C macro to help determind the max number of characters that an unsigned long can hold?
something maybe like,
char str[MAX_NUMBER_OF_DIGITS_OF_UNSIGNED_LONG_ON_MACHINE];
I've skimmed throught limits.h and a few blogs and this forum but with no accord. Any help would be appreciated!