Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

cs9tmf

String problems

This topic is 5638 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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 );
}

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!