Convert to ASCII ?
-
This seems very silly and basic - The function description is pretty clear Convert an unsigned long integer into a string, using a given base So why I keep printing numbers and NOT ASCII letter? I need a pointer to string - not numeric value. And I am sorry to ask such stupid question. Cheers Vaclav
int base = 10;
long value = 73;
char buffer[33];
unsigned long RANDOM = random(65, 79);for( base = 2; base <= 16; base = base + 2 ) { printf( "%2d %s\\n", base, ultoa( RANDOM, buffer, base ) ); }
-
This seems very silly and basic - The function description is pretty clear Convert an unsigned long integer into a string, using a given base So why I keep printing numbers and NOT ASCII letter? I need a pointer to string - not numeric value. And I am sorry to ask such stupid question. Cheers Vaclav
int base = 10;
long value = 73;
char buffer[33];
unsigned long RANDOM = random(65, 79);for( base = 2; base <= 16; base = base + 2 ) { printf( "%2d %s\\n", base, ultoa( RANDOM, buffer, base ) ); }
-
This seems very silly and basic - The function description is pretty clear Convert an unsigned long integer into a string, using a given base So why I keep printing numbers and NOT ASCII letter? I need a pointer to string - not numeric value. And I am sorry to ask such stupid question. Cheers Vaclav
int base = 10;
long value = 73;
char buffer[33];
unsigned long RANDOM = random(65, 79);for( base = 2; base <= 16; base = base + 2 ) { printf( "%2d %s\\n", base, ultoa( RANDOM, buffer, base ) ); }
-
This seems very silly and basic - The function description is pretty clear Convert an unsigned long integer into a string, using a given base So why I keep printing numbers and NOT ASCII letter? I need a pointer to string - not numeric value. And I am sorry to ask such stupid question. Cheers Vaclav
int base = 10;
long value = 73;
char buffer[33];
unsigned long RANDOM = random(65, 79);for( base = 2; base <= 16; base = base + 2 ) { printf( "%2d %s\\n", base, ultoa( RANDOM, buffer, base ) ); }
Try this:
for( base = 2; base <= 16; base = base + 2 ) { ultoa( RANDOM, buffer, base ); printf( "%2d %s\\n", base, buffer ); }
The difficult we do right away... ...the impossible takes slightly longer.
-
Vaclav_Sal wrote:
So why I keep printing numbers
Because that is what
ultoa
creates. It takes a numeric value (long) and converts it to printable characters. Try an input value of 127 instead of RANDOM. -
So itoa is really NOT "integer to ASCII" conversion, right? I knew it was a silly question. I suppose I can use some kind of lookup method the get from random index # to character array of alphabet. I'll check stdio. Thanks
-
So itoa is really NOT "integer to ASCII" conversion, right? I knew it was a silly question. I suppose I can use some kind of lookup method the get from random index # to character array of alphabet. I'll check stdio. Thanks