Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#Actualnfactorial

Posted 07 February 2013 - 08:27 AM

The first string you pass to sprintf is the format specifier, so if you did:

 

sprintf( title, g_engine->getAppTitle().c_str() );

and your app title had (for example) "%d" in it (eg. "%data manager%") the sprintf would look for an integer and replace the %d with it, which would usually be some garbage from the stack. It might seem obvious in this contrived example, but can more difficult depending on what 'accidental' specifier is in the string and what is on the stack, avoiding any issues completely is always more preferable.

 

In the particular example you gave, there isn't any particular need to use sprintf however. It may as well be a simple string copy.

 

n!


#2nfactorial

Posted 07 February 2013 - 08:26 AM

The first string you pass to sprintf is the format specifier, so if you did:

sprintf( title, g_engine->getAppTitle().c_str() );

and your app title had (for example) "%d" in it (eg. "%data manager%") the sprintf would look for an integer and replace the %d with it, which would usually be some garbage from the stack. It might seem obvious in this example, but can more difficult depending on what 'accidental' specifier is in the string and what is on the stack.

 

In the particular example you gave, there isn't any particular need to use sprintf however. It may as well be a simple string copy.

 

n!


#1nfactorial

Posted 07 February 2013 - 08:25 AM

The first string you pass to sprintf is the format specifier, so if you did:

 

sprintf( title, g_engine->getAppTitle().c_str() ); and your app title had (for example) "%d" in it (eg. "%data manager%") the sprintf would look for an integer and replace the %d with it, which would usually be some garbage from the stack. It might seem obvious in this example, but can more difficult depending on what 'accidental' specifier is in the string and what is on the stack.

 

In the particular example you gave, there isn't any particular need to use sprintf however. It may as well be a simple string copy.

 

n!


PARTNERS