itoa <standard C lib. stdlib.h> What Maple library is this function itoa in?
itoa What Maple library is this function in?
(8 posts) (4 voices)-
Posted 5 years ago #
-
Thanks ... for those who would also need this function itoa "integer to ASCII"
to eaisly write to a LCD here it is.../* Ansi C "itoa" based on Kernighan & Ritchie's "Ansi C":
*/
void strreverse(char* begin, char* end) {
char aux;
while(end>begin)
aux=*end, *end--=*begin, *begin++=aux;
}
void itoa(int value, char* str, int base) {
static char num[] = "0123456789abcdefghijklmnopqrstuvwxyz";
char* wstr=str;
int sign;// Validate base
if (base<2 || base>35){ *wstr=''; return; }// Take care of sign
if ((sign=value) < 0) value = -value;// Conversion. Number is reversed.
do *wstr++ = num[value%base]; while(value/=base);
if(sign<0) *wstr++='-';
*wstr='';// Reverse string
strreverse(str,wstr-1);
}Posted 5 years ago # -
Maybe the formatting of the post formatter, eat some characters, '' is not a valid character.
I assume it should have been,'\'
, that is the four characters'
,\\
,0
and'
LeafLabs: I tried to get this right, using backquotes, and I couldn't.
Posted 5 years ago # -
Hope this will fix it - for some reason my cut and paste did not work?
It did it again ... it is THIS website that is messing up my paste?????
It does not like the "aspos fwd slash zero aspos and semicolon" after the two *wastr=/* Ansi C "itoa" based on Kernighan & Ritchie's "Ansi C": */
void strreverse(char* begin, char* end) {
char aux;
while(end>begin)
aux=*end, *end--=*begin, *begin++=aux;
}
void itoa(int value, char* str, int base) {
static char num[] = "0123456789abcdefghijklmnopqrstuvwxyz";
char* wstr=str;
int sign;// Validate base
if (base<2 || base>35)
{ *wstr='''; //<----------------<<<<<<<<<<<<
return; }// Take care of sign
if ((sign=value) < 0) value = -value;// Conversion. Number is reversed.
do *wstr++ = num[value%base]; while(value/=base);
if(sign<0) *wstr++='-';
*wstr=''; //<--------------------------<<<<<<<<<<<<<<<<<// Reverse string
strreverse(str,wstr-1);
}void setup() {
}
void loop() {
}
Posted 5 years ago # -
They need to go to a more professional board/forum like the Arduino.
Posted 5 years ago # -
Try putting your code between back-tick (`) characters. It will preserve formatting etc.
Posted 5 years ago # -
I did put the characters between back-ticks. It still removed formatting.
Even more frustrating is the the backslash characters are consumed, so if you edit a piece of text, backslashes disappear :-(Posted 5 years ago #
Reply
You must log in to post.