Click here to Skip to main content
15,891,784 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
puttextxy( int x, int y, string str);

How can I use the string arguments as like we do in printf() function.

I mean to say that I want to insert a string like printf("%d",var) can I use same syntax for string argument of puttextxy() function
Posted
Comments
Sergey Alexandrovich Kryukov 27-Dec-14 1:42am    
There is no such thing as "C++ graphics". It depends on platform.
—SA
[no name] 27-Dec-14 2:23am    
Solved myself.
Thanks alot.
Sergey Alexandrovich Kryukov 27-Dec-14 2:27am    
Nothing. Good luck, call again.
—SA

Got My Answer

C
char str[100];
sprintf(str,"(%d,%d)",x,y);
outtextxy(x,y,str);


C library function - sprintf()[^]
 
Share this answer
 
you could wrap the supplied puttextxy function in your own code to provide this eg

C++
Shrikshel_puttextxy(int x, int y, string format, ...)
{
   string formatted_str = "";
   // form a string using format and varargs from ...
  
   puttextxy(x, y, formatted_str);
}


you'd then call your routine like :-

C++
Shrikshel_puttextxy(5,10,"%d",150);

you'd need to read up on using variable length arguments 'varargs' using '...' but its not too hard
 
Share this answer
 
Comments
[no name] 27-Dec-14 1:58am    
This is not working...
char str[] = "%d,%d",x,y;

but its only shoing the "%d,%d"
please check..
Garth J Lancaster 27-Dec-14 2:25am    
well, that's quite obvious - did you read up on 'varargs' ?

you need to do something like

char str[2048];
va_list arg;
va_start(arg, format);
vsnprintf(str, sizeof str, format, arg);
va_end(arg);

in your wrapper function to get your formatted string

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900