Non-decimal radices/Convert: Difference between revisions
Content added Content deleted
m (→{{header|C}}) |
|||
Line 232: | Line 232: | ||
<lang c>#include <stdlib.h> |
<lang c>#include <stdlib.h> |
||
#include <string.h> |
#include <string.h> |
||
#include <assert.h> |
|||
#define MAX_OUTSTR_LEN 65 |
#define MAX_OUTSTR_LEN 65 |
||
Line 260: | Line 261: | ||
long from_base(const char *num_str, int base) |
long from_base(const char *num_str, int base) |
||
{ |
{ |
||
char *endptr; |
|||
int result = strtol(num_str, &endptr, base); |
|||
⚫ | |||
assert(*endptr == '\0'); /* if there are any characters left, then string contained invalid characters */ |
|||
⚫ | |||
return result; |
|||
⚫ | |||
⚫ | |||
}</lang> |
}</lang> |
||