C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 02-11-2003, 05:38 PM   #1
Registered User
 
Join Date: Feb 2003
Posts: 5
itoa

Hi
I am trying to get an allegro game/tutorial working on linux and found out itoa is not a good way to convert integer to ascii but I am having trouble implementing the substitution I found by searching the internet.

sprintf(buf, "%d", intval);

The lines in the code giving me the problem are

textout(buffer,pong_datafile[pong_text].dat,"Player 1 Score:",150,0,254);
textout(buffer,pong_datafile[pong_text].dat,itoa(score_p1,NULL,10),text_length(pong_dataf ile[pong_text].dat,"Player 1 Score:")+150,0,10);
textout(buffer,pong_datafile[pong_text].dat,"Player 2 Score:",350,0,254);
textout(buffer,pong_datafile[pong_text].dat,itoa(score_p2,NULL,10),text_length(pong_dataf ile[pong_text].dat,"Player 2 Score:")+350,0,10);

itoa is used (I suppose) to convert a number extracted from the pong.dat file to text. I can delete the two lines containing the itoa and it compiles fine of course.

How should sprintf be implemented in this context?

Thanks
coldcoyote is offline   Reply With Quote
Old 02-11-2003, 06:53 PM   #2
End Of Line
 
Hammer's Avatar
 
Join Date: Apr 2002
Posts: 6,240
Well, guessing that the 3rd parameter of textout() is a char*, you'd need to use sprintf() on a line of its own, and then put the buffer into textout().

Something like:

Code:
char buf[BUFSIZ];

sprintf (buf, "%d", num);
textout(buffer,pong_datafile[pong_text]. dat,buf,text_length(pong_datafile[pong_text].dat,"Player 2 Score:")+350,0,10);
But I don't have textout() or itoa(), so I can't test it for you.
__________________
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Hammer is offline   Reply With Quote
Old 02-12-2003, 12:27 PM   #3
Registered User
 
Join Date: Feb 2003
Posts: 5
Thanks!

sprintf (buf, "%d", score_p1);
textout(buffer,pong_datafile[pong_text].dat,"Player 1 Score:",150,0,254);
textout(buffer,pong_datafile[pong_text].dat,buf,text_length(pong_datafile[pong_text].dat,"Player 1 Score:")+150,0,10);
textout(buffer,pong_datafile[pong_text].dat,"Player 2 Score:",350,0,254);
sprintf (buf, "%d", score_p2);
textout(buffer,pong_datafile[pong_text].dat,buf,text_length(pong_datafile[pong_text].dat,"Player 2 Score:")+350,0,10);

and I am in business. For char buf[bufsize] I just a put large enough a number to work:-)
Thanks again. I learned something!
coldcoyote is offline   Reply With Quote
Old 02-12-2003, 04:35 PM   #4
End Of Line
 
Hammer's Avatar
 
Join Date: Apr 2002
Posts: 6,240
>>For char buf[bufsize] I just a put large enough a number to work
BUFSIZ (note the caps) is defined in stdio.h already. I can't guarantee what size it is set to, open your stdio.h file and have a look for it.
__________________
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Hammer is offline   Reply With Quote
Old 02-13-2003, 09:28 AM   #5
Registered User
 
Join Date: Feb 2003
Posts: 5
OOPS! I jumped to the conclusion that it was something I had to deal with since you included it in your example. There I go asuming again! I will look at it as soon as get back to my linux box. If it were not for Linux I would not have a stdio.h to look in to.

Thanks!
coldcoyote is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem using itoa g_p C Programming 2 05-03-2008 06:38 AM
Problem with itoa() perhaps? TheSquid C++ Programming 5 05-08-2006 02:04 AM
Really Weird itoa Problem Grantyt3 C++ Programming 8 12-20-2005 12:44 AM
itoa undeclared? curlious C++ Programming 16 12-11-2004 05:30 PM
itoa Thantos C Programming 2 09-18-2001 02:23 PM


All times are GMT -6. The time now is 10:42 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22