pgPrint question

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
JJPeerless
Posts: 82
Joined: Mon Jun 20, 2005 3:32 am

pgPrint question

Post by JJPeerless »

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
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

sprintf()?
JJPeerless
Posts: 82
Joined: Mon Jun 20, 2005 3:32 am

Post by JJPeerless »

well yea..i tried that..but then when i copmile it gets all angry

says

"undefined reference to sprintf"
annerajb
Posts: 40
Joined: Thu Mar 31, 2005 6:16 am

Post by annerajb »

could you post the code and with what are you compiling
JJPeerless
Posts: 82
Joined: Mon Jun 20, 2005 3:32 am

Post by JJPeerless »

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'
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

Link with libc (pass -lc on the linker command line)?
MrSiir[S]
Posts: 32
Joined: Tue Sep 14, 2004 11:08 am

Post by MrSiir[S] »

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: Select all

#define MAX_LENGTH 32+1

char* _ltoa&#40;char* buf, long i, int base&#41;
&#123;
    char reverse&#91;MAX_LENGTH+1&#93;;	// plus one for the null
    char* s;
    char sign = i < 0;

    i = labs&#40;i&#41;;
    reverse&#91;MAX_LENGTH&#93; = 0;
    s = reverse+MAX_LENGTH;
    do &#123;
        *--s = "0123456789abcdefghijklmnopqrstuvwxyz"&#91;i % base&#93;;
        i /= base;
    &#125; while &#40;i&#41;;
    if &#40;sign&#41; *--s = '-';
    return strcpy&#40;buf, s&#41;;
&#125;
Post Reply