Page 1 of 1
C68 function itoa
Posted: Sun Jul 15, 2018 5:32 pm
by Whopper
I'm hoping that you gurus can help me with a small problem.
I am building a disassembler in C68 (its for fun, don't judge.) I want to use the itoa function to convert a decimal address into hex.
I am using code based on this -
Code: Select all
int main()
{
int i = 0;
long ad;
char buff[7];
ad = 43981;
itoa(ad,buff,16);
printf("buff = %s\n", buff);
return 0;
}
When this is compiled on the PC it works. Transposing it to the Q68 and I get an error "Parameter count incorrect for function itoa."
Does anyone know of the syntax of the C68 itoa function? I'm a bit stumped at the moment.
Whopper
Re: C68 function itoa
Posted: Sun Jul 15, 2018 6:15 pm
by Derek_Stewart
Hi,
The itoa function is defined in "stdlib.h"
Have you included the stdlib.h begore the main() function.
The C68 documentation says:
char * itoa (int number, char * target)
looks two parameters: number and pointer to target
Re: C68 function itoa
Posted: Sun Jul 15, 2018 6:19 pm
by NormanDunbar
Afternoon Whopper,
C68 is, how shall I put it, a tad out of date, it's pre-ANSI, never mind anything else, however, it is the best we have, so we have to deal with it's foibles.
Your code should probably look like this:
Code: Select all
#include <stdio_h>
#include<stdlib_h>
int main(int arcg, char *argv[])
{
int i = 0;
long ad;
char buff[7];
ad = 43981;
itoa(ad,buff);
printf("buff = %s\n", buff);
return 0;
}
in stdlib_h, itoa is defined as:
If you need hex/octal/binary conversions, you will want:
Code: Select all
long strtol(const char *, char **, int);
unsigned long strtoul(const char *, char **, int);
Details and examples at
https://www.systutorials.com/docs/linux/man/3-strtoul/.
Have fun.
Cheers,
Norm.
Re: C68 function itoa
Posted: Sun Jul 15, 2018 8:29 pm
by Whopper
Norm,
Thanks for this information.
I fudged it with a switch statement and 16 cases.
Kludgy but its working.
I don't mind messing around like this as I am learning C as a pass time. I am so used to SQL that there is no common ground to strat of off. I have used Arduinos and RPi before, but only for trivial things.
Whopper
Re: C68 function itoa
Posted: Sun Jul 15, 2018 11:45 pm
by NormanDunbar
Sql?
Code: Select all
Select to_char(43981, 'XXXXXX') from dual;
That should do the trick, in Oracle at least, which is where I spend my working week as a DBA.
Cheers,
Norm.
Re: C68 function itoa
Posted: Mon Jul 16, 2018 4:34 pm
by Whopper
Norm,
For my sins I worked with MS SQL Server (of a number of versions.) Still it kept me off the streets.
Whopper
Re: C68 function itoa
Posted: Mon Jul 16, 2018 5:24 pm
by NormanDunbar
We all have our cross to bear.
Re: C68 function itoa
Posted: Mon Jul 16, 2018 5:33 pm
by Whopper
Norm,
Yes. I always told my family & friends (when I found one) that I was an England Goalie, because I was so ashamed.
Whopper