![]() |
| | #1 |
| Registered User Join Date: Feb 2003
Posts: 5
| itoa 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 | |
| | #2 |
| End Of Line 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);
__________________ When all else fails, read the instructions. If you're posting code, use code tags: [code] /* insert code here */ [/code] |
| Hammer is offline | |
| | #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 | |
| | #4 |
| End Of Line 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 | |
| | #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 | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |