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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:27:32+00:00 2026-06-14T10:27:32+00:00

Hello I am new to programming and I am writing a program in C.

  • 0

Hello I am new to programming and I am writing a program in C.

In my header file I have this macro:

#define yesno(c) (c==ENTER || c==' ' || c=='\t') ? ENTER : ESC

In my program I have this code

char keypressed()
{ char c;
c =getch();
return yesno(getch());
 }

So what I wanted to ask is why when I ask to return yesno(c) I have to press the button only once, while when I use return yesno(getch()) I have to press the button one two or three more times?

Is there a problem with getch() when called from a macro?

  • 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-14T10:27:34+00:00Added an answer on June 14, 2026 at 10:27 am

    because when you use

    yesno(getch());
    

    It expands to :

    (getch()==ENTER || getch()==' ' || getch()=='\t') ? ENTER : ESC`
    

    When the macro is expanded like this, it means that getch() could actually be called 1, 2 or 3 times because the logical || means:

    getch() == '\n' ? if true return ENTER, false test next one
    getch() == ' '  ? if true return ENTER, false test next one
    getch() == '\t' ? if true return ENTER, false return ESC
    

    If you use the gcc compiler you can find out what your macro expands to by using the -E flag:

    gcc -E myprog.c -o mprog.m
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to programming.I have seen this code.returning a derived class object to
Hello I am new to android programming, I haven't started writing the code for
I'm new at programming, new on this site too, so hello... I'm attempting to
hello I am new here and in programming as well. Today I have been
Hello I'm really new to the Python programming language and i have encountered a
I'm new to C programming and I have to write a program that picks
hello I'm new to PHP programming and I migrated from ASP .net to PHP..
hello im new to python and have been reading over the documentation and am
Hello.Am new to ios development.What have to do for NSOpenPanel to work in the
Hello I am new to assembly and I'm struggling to get a two-part program

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.