Switch type of base parameter to better handle corner cases

This commit is contained in:
Juhani Krekelä 2022-11-21 07:30:13 +02:00
parent 17a13cc101
commit cba8f303a9
3 changed files with 5 additions and 5 deletions

View File

@ -7,7 +7,7 @@
static bool baseconv_internal(
char outbuf[], size_t bufsize,
const char *digits, unsigned base,
const char *digits, size_t base,
uintmax_t num
) {
// Supported bases are 2 to number of digits inclusive
@ -48,7 +48,7 @@ static bool baseconv_internal(
return true;
}
bool baseconv(char outbuf[], size_t bufsize, unsigned base, uintmax_t num) {
bool baseconv(char outbuf[], size_t bufsize, size_t base, uintmax_t num) {
const char *digits = "0123456789abcdefghijklmnopqrstuvwxyz";
return baseconv_internal(outbuf, bufsize, digits, base, num);
}

View File

@ -1,2 +1,2 @@
bool baseconv(char outbuf[], size_t bufsize, unsigned base, uintmax_t num);
bool baseconv(char outbuf[], size_t bufsize, size_t base, uintmax_t num);
bool baseconv_digits(char outbuf[], size_t bufsize, const char *digits, uintmax_t num);

4
main.c
View File

@ -15,9 +15,9 @@ int main(void) {
return 1;
}
unsigned base;
size_t base;
printf("Base? ");
if (scanf("%u", &base) != 1) {
if (scanf("%zu", &base) != 1) {
fprintf(stderr, "Invalid input\n");
return 1;
}