Solved

Writing a simple program

Posted on 2000-02-25
10
185 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
  • 3
  • 2
  • 2
  • +3
10 Comments
 

Expert Comment

by:serp_mage
Comment Utility
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
Comment Utility
What is "to the cursor"?
serp_mage's or what?
0
 
LVL 10

Expert Comment

by:RONSLOW
Comment Utility
serp_mage seems to have answered it .. suggest you put it up as an answer.
0
 
LVL 22

Expert Comment

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

Expert Comment

by:nutsnuts
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:ciaran_g
Comment Utility
Adjusted points to 100
0
 

Author Comment

by:ciaran_g
Comment Utility
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
Comment Utility
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
Comment Utility
That just what i want, thats great, thanks a lot, really appreciate it
0
 
LVL 10

Expert Comment

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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now