Advertisement

problem with chars

Started by June 05, 2000 08:21 PM
5 comments, last by gameprogrammerwiz 24 years, 6 months ago
here is a cut-down version of my code: ============================================================ char textbuff[100]; char* log_1; char* log_2; char* log_3; void draw_log(char* log_in); void main() { if(KEY_DOWN(VK_RETURN)) { draw_log("hello"); } } void draw_log(char* log_in) { log_1 = log_2; log_2 = log_3; log_3 = log_in; sprintf(textbuff, "%c", log_1); drawtext(log_1, 300, 300, 1); sprintf(textbuff, "%c", log_2); drawtext(log_2, 300, 315, 1); sprintf(textbuff, "%c", log_3); drawtext(log_3, 300, 330, 1); } ============================================================ this works fine and dandy, but, instead of drawing "hello" to the screen, it draws ONE random character. i have no idea why...any ideas? p.s. this is supposed to work like the quake console...hence the: log_1 = log_2; log_2 = log_3; log_3 = log_in;
==============================
whats a signature?
htm[s]l[/s]
oops...i meant to type this:
sprintf(textbuff, "%c", log_1);
drawtext(textbuff, 300, 300, 1);
sprintf(textbuff, "%c", log_2);
drawtext(textbuff, 300, 315, 1);
sprintf(textbuff, "%c", log_3);
drawtext(textbuff, 300, 330, 1);

but i still have the problem
==============================
whats a signature?
htm[s]l[/s]
Advertisement
In your draw log function, the argument is a pointer to a location in memory. When you pass the "hello" into the functoin, it is not a memory location;


"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
ok, i have no idea how to fix that
==============================
whats a signature?
htm[s]l[/s]
#include void main(){char* temp = new char[30]; // enough spaces to hold text stringif(KEY_DOWN(VK_RETURN)){strcpy(temp, "hello");draw_log(temp);}}    


"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
Well I see 2 problems.

First of all you''ll be causing memory problems if you use the following call:

draw_log("hello");

printf will continue printing until it finds a null terminator somewhere in memory. so change that line to this:

draw_log("hello\0");

Second:

%c is used to print out a single character at a time so you have two choices you can do this:


sprintf(textbuff, "%c%c%c%c%c%c", log_1);

or you can do it the easy way:

sprintf(textbuff, "%s", log_1);

the %s is used for strings.
Joseph FernaldSoftware EngineerRed Storm Entertainment.------------------------The opinions expressed are that of the person postingand not that of Red Storm Entertainment.
Advertisement
thanks, eva!
==============================
whats a signature?
htm[s]l[/s]

This topic is closed to new replies.

Advertisement