Behalf Of Matthew Johnson
charcannotconvert to char…
Well I tried using the & in front it didn’t work, the problem seems to be
that track[0].id is an unsigned char * and I need a regular char* both of
them say char* in them but only one says unsigned.
I also must be hopeless cause I tried doing something very similar to your
example for putting numbers into text.
int songTrack[256];
int CDIndex;
CDIndex = 4; //start playing track 5
sprintf(songTrack,"%i",CDIndex);
PixelText(&songTrack,20,20);
And received a cannot convert a char (*) [256] to a char * error.
I do appreciate the help though.
It appears that you have songTrack declared as an integer array and not a
character array.
Try:
char songTrack[256];
int CDIndex;
CDIndex = 4; //start playing track 5
sprintf(songTrack,"%i",CDIndex);
PixelText(&songTrack,20,20);
Ken Rogoway
Homebrew Software
http://www.homebrewsoftware.com/
If it’s saying “cannot convert unsigned char to char *” the problem is
that you are passing a char where it is expecting a pointer to char so
just toss a & in front of what you are passing and it should be ok!
If you are looking to turn a number into a string here’s how…
char Buffer[256];
int I;
I=20000;
sprintf(Buffer,"%i",I);
then after that, buffer will be “20000”.
Hope that helps!
Alan
[mailto:sdl-bounces at lists.libsdl.org] On Behalf Of Matthew Johnson
SDL-announce)
cannotconvert to char*…
And here I thought I wouldn’t need help. Turns out I was wrong again.
I decided as a fun little project to make a CD Player. I know, lame,
but I am still a beginner. And I thought it would be a fun project.
Anywho, in order to see what was playing and how far along I was in
the song I needed to draw the id of the track. And I did this using a
small function I made.
In order to make the placing of text easier on my screen I put all of
the font rendering pieces in a small function I called PixelText()
here’s what it looks like
void PixelText(char* text, int textx, int texty) {
textDraw = TTF_RenderText_Solid(mainFont, text, fontColor);
SDL_Rect rcSrc;
SDL_Rect rcDst;
//source rectangle
rcSrc.x=rcSrc.y=0;
rcSrc.w=textDraw->w;
rcSrc.h=textDraw->h;
//destination rectangle
rcDst=rcSrc;
rcDst.x=textx;
rcDst.y=texty;
//blit the surface
SDL_BlitSurface(textDraw,&rcSrc,mainScreen,&rcDst);
SDL_FreeSurface(textDraw);
}
Very simple, however as you can see it uses a char* just as is
required by TTF_RenderText_Solid(). And unfortunately
cdToPlay->track[0].id is an unsigned char*. So I can’t exactly just
use it like this.
PixelText(cdToPlay->track[0].id,10,20);
It comes up with this error when I try
PixelText’ : cannot convert parameter 1 from ‘unsigned char’ to 'char *'
Conversion from integral type to pointer type requires
reinterpret_cast, C-style cast or function-style cast
I’ve tried using reinterpret_cast but probably incorrectly I’ve even
done the simple (char*) cast and that doesn’t work. I really don’t
understand casting, could anyone help me here? What exactly would I
need to do to use the track id in my function?
Also how would I convert numbers to text? I’m assuming that uses the
same thing.
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.484 / Virus Database: 269.12.4/969 - Release Date: 8/23/2007
4:04 PM
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.484 / Virus Database: 269.12.4/969 - Release Date: 8/23/2007
4:04 PM
----- Original Message -----
From: sdl-bounces@lists.libsdl.org [mailto:sdl-bounces at lists.libsdl.org] On
Sent: Friday, August 24, 2007 12:08 AM
To: A list for developers using the SDL library. (includes SDL-announce)
Subject: Re: [SDL] Okay small problem using SDL_TTF…unsigned
On 8/23/07, Alan Wolfe wrote:
-----Original Message-----
From: sdl-bounces at lists.libsdl.org
Sent: Thursday, August 23, 2007 9:27 PM
To: A list for developers using the SDL library. (includes
Subject: [SDL] Okay small problem using SDL_TTF…unsigned char*