forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

_itoa question

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
cable16



Joined: 22 Mar 2005
Posts: 22

PostPosted: Wed Aug 10, 2005 3:10 am    Post subject: _itoa question Reply with quote

I recently installed cygwin, pspsdk, and the toolchain, and I'm having some problems getting _itoa(int n, char *buf, int radix) from stdlib to work. There's some code I have that used the pspsdk beta, and I'm trying to get it to work under my cygwin install now. When the code used the beta, I manually added an itoa function to my headers, because the beta's stdlib didn't have a itoa function back then. Now, the code uses the sdk's function, and it doesn't work right.

this leaves tmp empty:
Code:

#include <stdlib.h>

char *tmp = &freespace;
long long int offset = 33526363;

_itoa(offset, &tmp, 16);


this will leave tmp as "1FF925B":
Code:

// declared outright
char *test_itoa(int n, char *buf, int radix)
{
  char         *ret = buf;
  char         tmp[33];
  int          i = 0, j, r;

  /* validate the conversion number base. */
  if ((radix >= 2) && (radix <= 36)) {
    if ((radix == 10) && (n < 0)) {
      /* negative integer value. */
      *buf++ = '-';
      n = -n;
    }
    do {
      /* calculate the current digit. */
      r = (int)((unsigned int)n % radix);
      tmp[i++] = ((r < 10) ? (r + '0') : (r - 10 + 'a'));
    } while ((n /= radix) != 0);
    /* reverse the buffer string. */
    for (--i, j = 0; (i >= 0); --i, ++j) buf[j] = tmp[i];
    buf[j] = 0;
  }
  return (ret);
}

char *tmp = &freespace;
long long int offset = 33526363;

test_itoa(offset, &tmp, 16);
Back to top
View user's profile Send private message Visit poster's website AIM Address
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Wed Aug 10, 2005 4:55 am    Post subject: Re: _itoa question Reply with quote

this leaves tmp empty:
Code:

#include <stdlib.h>

char *tmp = &freespace;
long long int offset = 33526363;

_itoa(offset, &tmp, 16);

use _itoa(offset, tmp, 16); and then buy and read some C learning book ;-)
Back to top
View user's profile Send private message
cable16



Joined: 22 Mar 2005
Posts: 22

PostPosted: Thu Aug 11, 2005 1:50 am    Post subject: Reply with quote

ok, oops, that's a messup in the sample I posted, in the real code it uses like you said
Code:
_itoa(offset, tmp, 16);


The problem is, if I declare my own itoa function it will work correctly, but if I use the sdk's function in libpsplibc.a it won't work.

this doesn't work
Code:

#include <stdlib.h>

int main(void)
{
char *tmp = &freespace;
long long int offset = 33526363;

_itoa(offset, tmp, 16);
}


this does
Code:

char *test_itoa(int n, char *buf, int radix)
{
  char         *ret = buf;
  char         tmp[33];
  int          i = 0, j, r;

  /* validate the conversion number base. */
  if ((radix >= 2) && (radix <= 36)) {
    if ((radix == 10) && (n < 0)) {
      /* negative integer value. */
      *buf++ = '-';
      n = -n;
    }
    do {
      /* calculate the current digit. */
      r = (int)((unsigned int)n % radix);
      tmp[i++] = ((r < 10) ? (r + '0') : (r - 10 + 'a'));
    } while ((n /= radix) != 0);
    /* reverse the buffer string. */
    for (--i, j = 0; (i >= 0); --i, ++j) buf[j] = tmp[i];
    buf[j] = 0;
  }
  return (ret);
}

int main(void)
{
char *tmp = &freespace;
long long int offset = 33526363;

test_itoa(offset, tmp, 16);
}
Back to top
View user's profile Send private message Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group