473,387 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Reverse terminal output

mschenkelberg
I was wondering if it is easy to direct output in a scenario where the program gets user input from stdin and instead of outputting result on next line after use hits enter, it will output on same line user entered input.

Normally this happens because user must press enter to submit text
./test
Please enter a number: 32
You entered 32.

I would like to do this:
./test
Please enter a number: 32 You entered 32.

An example of a program that does this is gforth for the forth programming language. I was wondering if anyone knew how to do it with simple code.
Mar 10 '08 #1
5 2222
Sick0Fant
121 100+
It's a guess-- but try using the backspace escape sequence (?)

Something like

Expand|Select|Wrap|Line Numbers
  1. cout<<"Enter a number: ";
  2. cin>> number;
  3. cout<<"\bYou entered << number
  4.  
  5.  
Again, it's a guess.
Mar 10 '08 #2
It's a guess-- but try using the backspace escape sequence (?)

Something like

Expand|Select|Wrap|Line Numbers
  1. cout<<"Enter a number: ";
  2. cin>> number;
  3. cout<<"\bYou entered << number
  4.  
  5.  
Again, it's a guess.
Nope \b only delete up to beginning of current line. Thanks for the response though.
Mar 10 '08 #3
MACKTEK
40
You can do what you want to do using _getch() and _putch()
you will need #include <conio.h>

The _getch() will grab a keypress without echo to the screen.

So, you will have to write a program to handle what you want printed to the screen... using _putch()

So, for example you can write a loop using _getch and print out using _putch but not print when they press a space or an "enter" key.

You will also have to convert your input to valid numbers and throw away invalid data.

Also, there is no "backspace" or other line editing features "built in" to that, so you would have to either add them in or require the user to enter data according to the format you specify.
For example: In a small program I wrote, using the backspace did actually "backspace" but remember that "backspace" will not erase your previous input characters from any array you are building unless you add it in.
Mar 11 '08 #4
Thanks, but this program needs to run on linux. Are there equivalent linux functions?
Mar 11 '08 #5
MACKTEK
40
There seems to be a possible fix.
Using something called non-canonical mode.
I am not a linux programmer, so good luck.

http://cboard.cprogramming.com/archi...p/t-27714.html
Mar 11 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: flamesrock | last post by:
First, I'm very new to gui programming, so please go lightly on me :) Ok, so far I've settled on wxPython, and what I'd like to do as a first leap is *convert* a text program into a gui program....
1
by: Adriaan Renting | last post by:
I have the problem that I need to interact with a CD/DVD burning program called gear. I do this by running it in a pseudo terminal. I also need to log what I'm doing, so I copy all output I get...
5
by: James Leddy | last post by:
Hello, I need to write a program that will flash random numbers in the first line of output. The first number flashed will only remain on the screen for about 10 milliseconds. Then another...
20
by: Joel Hedlund | last post by:
Hi all! I use python for writing terminal applications and I have been bothered by how hard it seems to be to determine the terminal size. What is the best way of doing this? At the end I've...
10
by: aatish19 | last post by:
1: Write a program that asks the user to input an integer value and print it in a reverse order Sample Output Enter any number 65564 Reverse of 65564 is 46556 2: Write a program that takes a...
16
by: John Salerno | last post by:
Here's my new project: I want to write a little script that I can type at the terminal like this: $ scriptname package1 where scriptname is my module name and any subsequent arguments are the...
3
by: zubin | last post by:
i want to take input at the screen and at the same time flash the output on to the terminal (coming from some other process)...how do i go about it? the interface should look something like...
13
by: sayansayan | last post by:
two threads are running in a prog i need the output of one thread in a new terminal which the prog will create and the output of other thread in the old terminal
2
by: David | last post by:
Hi list. I've never used unicode in a Python script before, but I need to now. I'm not sure where to start. I'm hoping that a kind soul can help me out here. My current (almost non-existant)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.