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
Solved

Writing a simple program

Posted on 2000-02-25
10
189 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
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

807 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