Skip to main content
gamedev.net
🔒 Locked

printf problem

Started by TEUTON Mar 25, 2006 at 8:16 PM 3 replies 850+ views
Original Post
TEUTON
TEUTON
What does this statement means...I have never seen such a way of using printf and it's even working fine in VC6.0.

   printf("%d"+2,123);

if I enter 6 instead of 2 I start getting ftbuf.c what is this? For larger numbers I don't get any output. I have no idea what is going around.
Kambiz
Kambiz
Try this:
printf("%s","abcdefg"+2);
you will get:
"cdefg"

so "%d"+2 means "" and printf("%d"+2,123) is equal to printf("",123) and the output will be nothing!

"blah blah blah..." is a pointer to the string (a const char* I think) so "blah blah blah..."+n is a pointer to the n-th character of the string.
dave
dave
Well you learn something every day don't you.

Dave
TEUTON
TEUTON
Quote:
Original post by Dave
Well you learn something every day don't you.

Dave


Yes...that's right.
jonahrowley
jonahrowley
Character literals all get put into the same section. You can end up with pieces of an entierly different string, something from another section entirely (hate to see what happens when you try to print a jump table as a string), or if you're really unlucky, hit an address where there is no page mapped and pagefault.

Topic Locked

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

Sign in to reply to this topic.