Anonymous user
Non-decimal radices/Convert: Difference between revisions
m
→{{header|C}}
m (→{{header|C}}) |
|||
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;
// 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;
▲ /
}</lang>
|