Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7815177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:26:14+00:00 2026-06-02T05:26:14+00:00

I have been trying to get getch to work in another program with no

  • 0

I have been trying to get getch to work in another program with no success. So I have made the most basic program I can using getch the way I want it to work in the main program.

I have researched the need for noecho, cbreak, initscr and nodelay, I have also tried using newscr() but to no success.

The problem I am having is that the chars aren’t being printed to the screen till I hit “enter”, when they should be put to the screen every loop. Why is this happening? Also the cursor doesn’t return to the left of the screen at the new line. eg.

abc  
   def
      ghi

I have looked for the answer but am stumped again…

#include <stdio.h>
#include <ncurses.h>

int main()
  {
     initscr();cbreak(); noecho();nodelay(stdscr,0);
    char c ;
    while((c=getch())!=EOF){
    putchar(c);}

    return 0;
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:26:16+00:00Added an answer on June 2, 2026 at 5:26 am

    You’re not seeing the output because your stdout stream is line buffered.

    Your program is getting the individual characters all right; but the output stream is buffering them.

    Try fflush(stdout); or switching stdout to unbuffered mode with setbuf(stdout, NULL);.

    The problem with disabling buffering is that it’s inefficient for bulk data processing when the output isn’t a terminal.

    You can make it conditional on the standard output being a tty:

    if (isatty(fileno(stdout)))  /* #include <unistd.h> */
      setbuf(stdout, NULL);
    

    To return the cursor to the start of the line, you need to put out a carriage return \r. This is because curses’ cbreak mode has disabled the ONLCR tty mode (on Output, when sending NL add CR).

    If you unconditionally add \r, then it will appear in files when your output is redirected. So again you need some isatty hack.

    A much better might be to learn how to use the tcgetattr and tcsetattr functions to precisely control specific tty parameters, if all you want is to do character-at-a-time input without echo, and not actually develop an interactive curses-based program.

    Do you really want character-at-a-time input, or just to diable echo? It’s easy to disable echo. Call tcgetattr to fill a struct termios with the current settings of file descriptor 0 (if it is a tty). Flip some flags to turn off echoing, then call tcsetattr to install the updated structure. When your program exits, be nice and put back the original one. Done.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to get this to work and can't. I have a
I have been trying to get CodeDom to work so I can dynamically create
I have been trying to get this to work for most of the day
I have been trying to get this program to work but so far having
I have been trying to get nServiceBus to work with Ninject 2.0 as the
I have been trying to get LastBootUpTime using Win32_OperatingSystem class (WMI). HRESULT hr =
I have been trying to get this to work correctly and I think I
I have been trying to get this jsfiddle to work. So far without luck.
I have been trying to get this to work for 12 hrs now and
I have been trying to get a2billing to work for the past 4 days

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.