Solved

Writing a simple program

Posted on 2000-02-25
10
190 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
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!

 
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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
Excel/Word Add-in in what language? 5 144
Template syntax for variable length arrays 9 77
print bytes of an integer 6 29
C++ statement T∗ begin(Vector<T>& x) 5 16
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

697 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