Non-decimal radices/Convert: Difference between revisions

m
Line 232:
<lang c>#include <stdlib.h>
#include <string.h>
#include <assert.h>
 
#define MAX_OUTSTR_LEN 65
Line 260 ⟶ 261:
long from_base(const char *num_str, int base)
{
char *endptr;
returnint result = strtol(num_str, NULL&endptr, base);
// there is also strtoul() for parsing into an unsigned long
assert(*endptr == '\0'); /* if there are any characters left, then string contained invalid characters */
// in C99, there is also strtoll() and strtoull() for parsing into long long and unsigned long long, respectively
return result;
//* there is also strtoul() for parsing into an unsigned long */
//* in C99, there is also strtoll() and strtoull() for parsing into long long and unsigned long long, respectively */
}</lang>
 
Anonymous user