C68 function itoa

Anything QL Software or Programming Related.
User avatar
Whopper
Chuggy Microdrive
Posts: 74
Joined: Tue Oct 24, 2017 4:04 pm

C68 function itoa

Postby Whopper » Sun Jul 15, 2018 5:32 pm

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
QL Wafer Drive
Posts: 1110
Joined: Mon Dec 20, 2010 11:40 am
Location: Runcorn, Cheshire, UK

Re: C68 function itoa

Postby Derek_Stewart » Sun Jul 15, 2018 6:15 pm

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
Super Gold Card
Posts: 522
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: C68 function itoa

Postby NormanDunbar » Sun Jul 15, 2018 6:19 pm

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?
How come Tarzan never grew a beard?
If at first you don't succeed, don't take up skydiving!
If you think your job is pointless, remember, there's a man in Germany who fits indicators on BMWs.
User avatar
Whopper
Chuggy Microdrive
Posts: 74
Joined: Tue Oct 24, 2017 4:04 pm

Re: C68 function itoa

Postby Whopper » Sun Jul 15, 2018 8:29 pm

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
Super Gold Card
Posts: 522
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: C68 function itoa

Postby NormanDunbar » Sun Jul 15, 2018 11:45 pm

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?
How come Tarzan never grew a beard?
If at first you don't succeed, don't take up skydiving!
If you think your job is pointless, remember, there's a man in Germany who fits indicators on BMWs.
User avatar
Whopper
Chuggy Microdrive
Posts: 74
Joined: Tue Oct 24, 2017 4:04 pm

Re: C68 function itoa

Postby Whopper » Mon Jul 16, 2018 4:34 pm

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
Super Gold Card
Posts: 522
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: C68 function itoa

Postby NormanDunbar » Mon Jul 16, 2018 5:24 pm

We all have our cross to bear. ;)


Why do they put lightning conductors on churches?
How come Tarzan never grew a beard?
If at first you don't succeed, don't take up skydiving!
If you think your job is pointless, remember, there's a man in Germany who fits indicators on BMWs.
User avatar
Whopper
Chuggy Microdrive
Posts: 74
Joined: Tue Oct 24, 2017 4:04 pm

Re: C68 function itoa

Postby Whopper » Mon Jul 16, 2018 5:33 pm

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!!!

Return to “Software & Programming”

Who is online

Users browsing this forum: No registered users and 1 guest