Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
Hello
 
i'm trying to update a program that printed results to a DOS window to a text box in Visual C++ 2010
 

Regards,
Binu
Posted 11-Oct-12 7:03am
Comments
Sergey Alexandrovich Kryukov at 11-Oct-12 14:17pm
   
No, you don't have a problem printing anything to a DOS window. If you are using Visual Studio 2010, it can only run on systems which don't have a "DOS window"!
--SA
Wes Aday at 11-Oct-12 14:25pm
   
Thanks for keeping us up to date on your progress. Please let us know if you have an actual question related to a specific programming problem.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Well, first of all, please see my comment to the question.
 
Replace the function printf with sprintf which "prints" to a string:
http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/[^].
 
You can even avoid replacing the function name where it is currently used. Instead, wrap a call to sprintf into a function and name it printf; use this new function in your legacy code.
 
When all printing to a string is done, use this string to populate the text box value.
 
—SA
  Permalink  
Comments
CPallini at 11-Oct-12 15:34pm
   
My 5. However you probably overlooked the additional parameter of sprintf while suggesting the OP to replace printf in the legacy code (or maybe I didn't get you).
Sergey Alexandrovich Kryukov at 11-Oct-12 15:48pm
   
Thank you very much.
 
Yes, you are exactly right about this string parameter.
Well, no, I actually though about it, just left to the OP, as it could be worked around. Perhaps, I assumed too much about OP's ability to resolve it.
One way I can see to make it an instance property of some class, encapsulate the function with the class where it is used. In this case, the pointer to the string could be accessed through the "this" parameter of the "imitation printf" method.
 
Maybe, just changing the function name and adding the parameter throughout the code could be easier. It depends on the legacy code. I also don't know if the previously developed functionality writing in console should still be supported or not.
 
I hope it explains the approach to be used now.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

hi dear john
 
you have to do these :
 
we have a text(edit control) box and it named t.
write these code into a button to perform that.
CString s;
char *a=0;
USES_CONVERSION;
t.GetWindowText(s);
s=_T("echo ")+s+_T("\n pause");
a=T2A(s.GetBuffer());
system(a);
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 358
1 Sergey Alexandrovich Kryukov 236
2 PhilLenoir 179
3 ChauhanAjay 151
4 ClimerChinna 150
0 Sergey Alexandrovich Kryukov 6,205
1 OriginalGriff 5,333
2 CPallini 2,473
3 Richard MacCutchan 1,617
4 Abhinav S 1,530


Advertise | Privacy | Mobile
Web02 | 2.8.140814.1 | Last Updated 11 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100