nCurses getch() question - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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

Comments

  • IDKIDK Posts: 1,784Member
    : 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
    :

    Always remember the difference between ascii and binary numbers.
    '2' != 2

    I think the code you want looks something like this:

    [code]
    double one;
    one=getch()-'0';
    one=one*10+getch()-'0';
    [/code]


  • alpha_gammaalpha_gamma Posts: 2Member
    [b][red]This message was edited by alpha_gamma at 2007-3-6 17:23:34[/red][/b][hr]
    :
    : //I think the code you want looks something like this:
    :
    : [code]
    : double one;
    : one=getch()-'0';
    : one=one*10+getch()-'0';
    : [/code]


    --------------------------------------------------------------------

    Hello IDK,

    Thank you very much for your reply. I tried out the algorithm and it permits me to only enter 2 digits. I guess I'll have to work on a loop structure that will acccept numbers until enter is pressed.

    Thanks again,

    Andrew


Sign In or Register to comment.