Skip to main content
GameDev.net gamedev.net
🔒 Locked

String problems

Started by cs9tmf Apr 19, 2003 at 7:13 AM 1 replies 250+ views
Original Post
cs9tmf
cs9tmf
I know this is really easy but my brain just won''t work! I have: char gszLineNumber[MAX_PATH] = ""; char *szLineNumber = ""; szLineNumber = "Line Number : "; strcpy(gszLineNumber,szLineNumber); How would i append onto szLineNumber a integer value like 10? Please help me! cheers
Balthazaar
Balthazaar
Use sprintf.

Here an example from MSDN:


/* SPRINTF.C: This program uses sprintf to format various
* data and place them in the string named buffer.
*/

#include <stdio.h>

void main( void )
{
char buffer[200], s[] = "computer", c = ''l'';
int i = 35, j;
float fp = 1.7320534f;

/* Format and print various data: */
j = sprintf( buffer, "\tString: %s\n", s );
j += sprintf( buffer + j, "\tCharacter: %c\n", c );
j += sprintf( buffer + j, "\tInteger: %d\n", i );
j += sprintf( buffer + j, "\tReal: %f\n", fp );

printf( "Output:\n%s\ncharacter count = %d\n", buffer, j );
}
LightBrain website relaunched, BomberFUN only USD 9,99 - Look at http://www.lightbrain.de
thy MC
thy MC
My brain isn''t working either but I remember this

char buf[MAX_PATH];

int wrongid=10001;
sprintf("This boy has wrong ID -> %d it is wrong, right ? ",
wrongid);

or ... use ftoa
Please AGREE or I will LIBERATE you

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.