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 6938319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:28:39+00:00 2026-05-27T12:28:39+00:00

I am writing a simple Objective – C console app. I only want to

  • 0

I am writing a simple Objective – C console app.
I only want to accept digits.
Even if i type a character which is not a digit, it should not be echoed back.
and I should have a character array that has all digits on which i can use atoi().

scanf has formatters but they dont work the way i want.
I know it should be possible. The way it works when u enter passwords in terminal,
they are just accepted but not echoed back.

I just want a variation of it.

Is there some C function that only accepts a character and returns it but doesn’t echoes it back on screen ?

  • 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-05-27T12:28:40+00:00Added an answer on May 27, 2026 at 12:28 pm

    Check out these link for more info What is Equivalent to getch() & getche() in Linux?

    you can use getch() but if there is no getch() then you can try the below code.

    #include <termios.h>
    #include <stdio.h>
    
    static struct termios old, new;
    
    /* Initialize new terminal i/o settings */
    void initTermios(int echo) 
    {
      tcgetattr(0, &old); /* grab old terminal i/o settings */
      new = old; /* make new settings same as old settings */
      new.c_lflag &= ~ICANON; /* disable buffered i/o */
      new.c_lflag &= echo ? ECHO : ~ECHO; /* set echo mode */
      tcsetattr(0, TCSANOW, &new); /* use these new terminal i/o settings now */
    }
    
    /* Restore old terminal i/o settings */
    void resetTermios(void) 
    {
      tcsetattr(0, TCSANOW, &old);
    }
    
    /* Read 1 character - echo defines echo mode */
    char getch_(int echo) 
    {
      char ch;
      initTermios(echo);
      ch = getchar();
      resetTermios();
      return ch;
    }
    
    /* Read 1 character without echo */
    char getch(void) 
    {
      return getch_(0);
    }
    
    /* Read 1 character with echo */
    char getche(void) 
    {
      return getch_(1);
    }
    
    /* Let's test it out */
    int main(void) {
      char c;
      printf("(getche example) please type a letter: ");
      c = getche();
      printf("\nYou typed: %c\n", c);
      printf("(getch example) please type a letter...");
      c = getch();
      printf("\nYou typed: %c\n", c);
      return 0;
    } 
    

    Getch function gets the characters but does not echo to screen.

    Thanks

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

Sidebar

Related Questions

I am writing a simple console application in Objective-C but I have heard that
I am writing simple program for my Ubuntu 10.04. I want to see which
I was writing a simple console application in Objective C. I have tried system(clear)
I'm writing a simple OpenGL application that uses GLUT . I don't want to
I'm writing a simple app that's going to have a tiny form sitting in
I am currently writing a simple, timer-based mini app in C# that performs an
I'm just getting started with Objective-C and I'm writing a simple application. I made
I'm writing an iPhone app where I'd like to display some simple musical notation
I'm writing an iPhone app which downloads a tar-gzipped file from a Webserver, then
I'm writing simple Android app to filter some events from user's calendar. The questions

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.