 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
cable16
Joined: 22 Mar 2005 Posts: 22
|
Posted: Wed Aug 10, 2005 3:10 am Post subject: _itoa question |
|
|
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 |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Wed Aug 10, 2005 4:55 am Post subject: Re: _itoa question |
|
|
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 |
|
 |
cable16
Joined: 22 Mar 2005 Posts: 22
|
Posted: Thu Aug 11, 2005 1:50 am Post subject: |
|
|
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 |
|
 |
|
|
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
|