Page 1 of 1

How would I use strcat to add the number stored in a var?

PostPosted: Wed Jul 22, 2009 4:53 pm
by Hblade
I'm trying to make something that will add a textNumber. kinda like a timer but not exactly a timer, I'm using this code:
Code: Select all
double sec;
double minutes;
double hours;

I'm trying to make a fake clock, for a cutscene in the game, but I cant seem to add "hours, secs, and minutes" to the clock using strcat, is there any way that this can be done? My current code is
Code: Select all
strcpy(text, "");
    strcat(textNumber, hours);
    strcat(text, ":");
    strcat(textNumber, minutes);
    strcat(text, ":");
    strcat(textNumber, sec);

But that dosnt seem to work, I get this message


Error message.jpg

Re: How would I use strcat to add the number stored in a var?

PostPosted: Wed Jul 22, 2009 5:44 pm
by makslane
You must use the sprint function, for example:

Code: Select all
sprintf(text, "The time is: %f:%f:%f", hours, minutes, sec);


Read more:
http://www.cplusplus.com/reference/clib ... o/sprintf/
http://www.cppreference.com/wiki/c/io/sprintf

Re: How would I use strcat to add the number stored in a var?

PostPosted: Wed Jul 22, 2009 5:45 pm
by Hblade
Wrong arduments for STRCPY it says

Re: How would I use strcat to add the number stored in a var?

PostPosted: Wed Jul 22, 2009 10:51 pm
by makslane
Sorry, use sprintf