| View previous topic :: View next topic |
| Author |
Message |
JJPeerless
Joined: 20 Jun 2005 Posts: 82
|
Posted: Wed Jun 22, 2005 9:35 am Post subject: pgPrint question |
|
|
say i have a int variable named score (which keeps track of your score in a game...)
and on the screen i want to print "Score: 234" where 234 is the itneger stored in score..
how do i go about sending something like pgPrint(x,y,color,"Score: " + score)
i cant figure it out.. thanks |
|
| Back to top |
|
 |
mrbrown
Joined: 17 Jan 2004 Posts: 1536
|
Posted: Wed Jun 22, 2005 10:05 am Post subject: |
|
|
| sprintf()? |
|
| Back to top |
|
 |
JJPeerless
Joined: 20 Jun 2005 Posts: 82
|
Posted: Wed Jun 22, 2005 10:23 am Post subject: |
|
|
well yea..i tried that..but then when i copmile it gets all angry
says
"undefined reference to sprintf" |
|
| Back to top |
|
 |
annerajb
Joined: 31 Mar 2005 Posts: 40
|
Posted: Wed Jun 22, 2005 10:36 am Post subject: |
|
|
| could you post the code and with what are you compiling |
|
| Back to top |
|
 |
JJPeerless
Joined: 20 Jun 2005 Posts: 82
|
Posted: Wed Jun 22, 2005 10:39 am Post subject: |
|
|
im using psp-gcc to compile everything..
ive added these includes
#include <stdlib.h>
#include <stdio.h>
and im using it as follows:
char buffer[20];
sprintf(buffer,"%i",score);
pgPrint(54,3,0xffff,"Score");
pgPrint(56,7,0xffff, buffer);
if "compiles" fine with psp-gcc
but the error comes in my main.o file
undefined reference to 'sprintf' |
|
| Back to top |
|
 |
mrbrown
Joined: 17 Jan 2004 Posts: 1536
|
Posted: Wed Jun 22, 2005 12:49 pm Post subject: |
|
|
| Link with libc (pass -lc on the linker command line)? |
|
| Back to top |
|
 |
MrSiir[S]
Joined: 14 Sep 2004 Posts: 32
|
Posted: Wed Jun 22, 2005 1:21 pm Post subject: |
|
|
use itoa(), if you don't have libc (ee-gcc), use custom function
| itoa wrote: | | char * itoa ( int value, char * buffer, int radix ); |
or, cutom ltoa function:
| Code: | #define MAX_LENGTH 32+1
char* _ltoa(char* buf, long i, int base)
{
char reverse[MAX_LENGTH+1]; // plus one for the null
char* s;
char sign = i < 0;
i = labs(i);
reverse[MAX_LENGTH] = 0;
s = reverse+MAX_LENGTH;
do {
*--s = "0123456789abcdefghijklmnopqrstuvwxyz"[i % base];
i /= base;
} while (i);
if (sign) *--s = '-';
return strcpy(buf, s);
} |
|
|
| Back to top |
|
 |
|