LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-04-2007, 07:42 PM   #1
alpha_gamma
LQ Newbie
 
Registered: Mar 2007
Posts: 11

Rep: Reputation: 0
nCurses getch() question


Hello,

I have begun using nCurses and am using getstr(name) to enter charaters and it is working well. However I would like to enter multi-digit numbers and tried this:

double one;
one=getch();

This only enables me to enter one character. I want to enter '22' but it only lets me enter '2'. All of the books and online resources say getch() will only grab one character.I have searched all the resources but they don't have the example I'm looking for to handle multi-digit input for one data variable. So as my last resort I am submitting my question here.

Can someone help me out and explain a way that I can enter multi-digit variables with getch() or some other nCurses function?

Thanks again,

Andrew
 
Old 03-04-2007, 08:10 PM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
You want wgetstr().

If you have not already done so, do these:

Code:
man ncurses
man curs_getch
man curs_getstr
If you have not already done so, go here:

http://web.cs.mun.ca/~rod/ncurses/ncurses.html#input
http://web.cs.mun.ca/~rod/ncurses/ncurses.html

Hope this helps.
 
Old 03-04-2007, 08:39 PM   #3
alpha_gamma
LQ Newbie
 
Registered: Mar 2007
Posts: 11

Original Poster
Rep: Reputation: 0
I gave it a try, g++ complained at me for passing an into for a string value. Actually this program calculates numerical values, so I can't enter the value as a string. I am looking for a way to enter the value like 'cin>>' and also seeing the numbers when entered.
 
Old 03-04-2007, 10:12 PM   #4
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
Look at istringstream for conversion. I believe it's in the sstream header.
 
Old 03-06-2007, 11:54 AM   #5
iamnothere
Member
 
Registered: Feb 2007
Location: UK
Distribution: Slamd 64, Slackware
Posts: 46

Rep: Reputation: 16
Quote:
Originally Posted by alpha_gamma
I can't enter the value as a string.
Yes, you can. If fact, that's all you can do. There is no such function as 'enter a number', you can only read characters, i.e. bytes of data. There is no distinction between digits and non-digits at the input level. Read a string, then convert it into an int/double with strtol/strtod.
 
Old 03-06-2007, 03:26 PM   #6
spaesani
LQ Newbie
 
Registered: Mar 2007
Posts: 13

Rep: Reputation: 0
man curs_scanw

good question
looks like you stumped a few people
)
(i looked it up)
of note is that many libc functions have curses equivalents
or vice versa.
cheers
sp
 
Old 03-06-2007, 07:39 PM   #7
alpha_gamma
LQ Newbie
 
Registered: Mar 2007
Posts: 11

Original Poster
Rep: Reputation: 0
Hello,

I currently have this algorithm, it only accepts 2 digits for input,
Code:
        while(bControlLoop){
	     one = getch()-'0';
	     one=one*10+getch()-'0';
	     if (!(one >= '0' && one <= '9')) bControlLoop = false;
         }

but I think I think 'iamnothere's suggestion of reading in a string and converting it to a double with strtol/strtod sounds very good. Or maybe just using scanf to get an integer, I have to look it up and apply it to my code and see how I can work it out. So far it is 300 lines of code in 9 files and I'm going to have to reformat everything to get it displaying nCurses in the terminal.

Thank you very much for your replies, I really do appreciate your help.

Andrew
 
Old 03-07-2007, 07:30 PM   #8
spaesani
LQ Newbie
 
Registered: Mar 2007
Posts: 13

Rep: Reputation: 0
Smile curses

your welcome
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to print text in color by ncurses without opening a ncurses window Greatrebel Programming 0 12-20-2006 09:15 AM
Question about building glibc and ncurses tomdkat Linux - Software 2 02-18-2005 09:59 AM
Equivalents of the getch() from conio.h in curses and ncurses aneeshm Programming 1 09-11-2004 07:19 AM
ncurses getch() deveraux83 Programming 3 08-06-2003 07:27 AM
ncurses-5.2-28 conflicts with file from package ncurses-5.2-12 tubby Linux - Software 4 06-16-2002 12:00 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration