Solved

Writing a simple program

Posted on 2000-02-25
10
192 Views
Last Modified: 2012-05-04
I was wondering if someone could tell me how, in C or C++, that i could print stuff from a program directly to the cursor. i know how to print things to .txt but no to the cursor in real time
Can anyone help
Thanks
0
Comment
Question by:ciaran_g
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +3
10 Comments
 

Expert Comment

by:serp_mage
ID: 2560543
If "to the cursor" means to the command line, or to a DOS window when using Visual C++, you have a couple options.  You can do the C thing:
e.g.,
#include <stdio.h>
.. . .
printf("what's up?\n");    

or you can do the C++ thing,
#include <iostream.h>  //might not need the ".h" suffix
.. . .
cout << "what's up?\n";
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2560671
What is "to the cursor"?
serp_mage's or what?
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2560772
serp_mage seems to have answered it .. suggest you put it up as an answer.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:nietod
ID: 2560821
And what OS is this for? and What compiler are you using?
0
 
LVL 1

Expert Comment

by:nutsnuts
ID: 2561135
If serp_mage has answered what "to the cursor" is, so I think you can put the output to a file like this:

#include <stdio.h>

   FILE *stream;
   int    i = 10;
   double fp = 1.5;
   char   s[] = "this is a string";
   char   c = '\n';

   stream = fopen( "output.txt", "w" );
   fprintf( stream, "%s%c", s, c );
   fprintf( stream, "%d\n", i );
   fprintf( stream, "%f\n", fp );
   fclose( stream );

That's it.
0
 

Author Comment

by:ciaran_g
ID: 2562453
Adjusted points to 100
0
 

Author Comment

by:ciaran_g
ID: 2562454
Sorry guys, i didn't make myself clear, say if i had a flashing cursor in a program, i minimse that, run my program and my program would print stuff out to that flashing cursor. maybe put a delay on my program and then get my program to print to wherever the cursor was flashing. i am using borland C++ 4.5. and i want to print stuff to a windows program (to where the cursor is flashing)
Thanks
0
 
LVL 22

Accepted Solution

by:
nietod earned 100 total points
ID: 2562631
Are you saying you want to "fake" keystrokes.  i.e. have our progream make the computer act like keys were types by the user?

The easiest way to do this is use keybd_event().  However, it only works if the program you want to have "receive" the keystrokes has the focus.  If the program doesn't have the focus, you can set the program WM_KEYDOWN and WM_KEYUP messages using sendmessage, however this tends to be harder to do and less reliable.
0
 

Author Comment

by:ciaran_g
ID: 2562797
That just what i want, thats great, thanks a lot, really appreciate it
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2563222
Shame you didn't say that in the first place :-).
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question