C68 function itoa

Anything QL Software or Programming Related.
Post Reply
User avatar
Whopper
Over Heated PSU
Posts: 126
Joined: Tue Oct 24, 2017 4:04 pm

C68 function itoa

Post 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


You woke me for THAT!!!
Derek_Stewart
Font of All Knowledge
Posts: 3928
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: C68 function itoa

Post 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
Last edited by Derek_Stewart on Sun Jul 15, 2018 6:29 pm, edited 1 time in total.


Regards,

Derek
User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: C68 function itoa

Post 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:

Code: Select all

char * itoa(int, char *);

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.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
Whopper
Over Heated PSU
Posts: 126
Joined: Tue Oct 24, 2017 4:04 pm

Re: C68 function itoa

Post 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


You woke me for THAT!!!
User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: C68 function itoa

Post 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.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
Whopper
Over Heated PSU
Posts: 126
Joined: Tue Oct 24, 2017 4:04 pm

Re: C68 function itoa

Post 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


You woke me for THAT!!!
User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: C68 function itoa

Post by NormanDunbar »

We all have our cross to bear. ;)


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
Whopper
Over Heated PSU
Posts: 126
Joined: Tue Oct 24, 2017 4:04 pm

Re: C68 function itoa

Post 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


You woke me for THAT!!!
Post Reply