I would like to print first N numbers in BASE62 encoding. What's wrong in my code?
const char ALPHABET[63] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(void) {
int N = 50;
for (int i = 0; i < N; i++) {
int base62 = ALPHABET[i % 62];
printf("Base 62: %s\n", (char*)base62);
}
}
You need to print out string representing the number in base62. For N >= 62, you will have a multi-character string. First, you would need to count the number of digits in the base62 representation and then display character-by-character.
For that, you need to something like this-