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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:54:07+00:00 2026-05-26T02:54:07+00:00

New programmer here with only some minor Java experience trying my hand at writing

  • 0

New programmer here with only some minor Java experience trying my hand at writing something in C. I want to ask someone a Yes/No question, do something depending on their answer, then ask them to press Enter to continue. I’m having two problems:

1.) I can’t get the program to accept ‘y’, ‘Y’, or “Yes” as answers. I can get it to accept one, but not all three. The “logical OR” operator || isn’t working.
2.) I can’t get it to stop at “Press Enter to Continue” without two “Flush” commands of:

while (getchar() != '\n');

The code I have and am trying to use is as follows:

int main (int argc, const char * argv[]) {
    printf("Would you like to continue? Please press y or n.\n");

    if(getchar() == 'y'){
        printf("You pressed yes! Continuing...");
    }
    else{
        printf("Pressed no instead of yes.");
    }
        //flush commands go here
    printf("\nPress ENTER to continue...");
    if(getchar()=='\n'){
        printf("\nGood work!");
    }else{
        printf("Didn't hit ENTER...");

    return 0;
}

Any help would be appreciated, thanks.

  • 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-26T02:54:07+00:00Added an answer on May 26, 2026 at 2:54 am

    Assuming that you are working in *nix environment,
    You can create a buffer to store the incoming characters one after the other.
    You have two cases:

    1. Single character input
    2. 3 character String
    

    For all other cases you can blindly say that the input is not OK!
    For case 1, i should be 1 and the character should be ‘y’ or ‘Y’
    For case 2, i should be 3 and the string should be ‘Yes’
    Any other case is incorrect. Here is the code:

    #include<stdio.h>
    int main()
    {
    char ch[3];
    char c;
    int i=0;
    while(((c=getchar())!='\n')){
            ch[i]=c;
            i++;
    }
    ch[i]='\0';
    if (i==1)
            if (ch[0]=='Y'||ch[0]=='y')
                    printf("OK");
            else
                    printf("Not OK");
    else if(i==3)
            if (strcmp(ch,"Yes")==0)
                    printf("OK");
            else
                    printf("Not OK");
    else
            printf("NOT OK");
    return 0;
    }
    

    I would recommend using something like this.

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

Sidebar

Related Questions

I am not an experienced Java programmer and i'm trying to write some text
New Programmer here. Trying space invaders. I have a 2 dimensional array of objects
N00b programmer here... Trying to store something into a string to use it in
New to OB-C here. Java programmer by trade. This is a sample from my
I'm a relatively new Java programmer coming from C++/STL, and am looking for a
Ok, So I want to display some attributes, but only if they have a
I am new here and points poor so I can only offer 50 pt
I'm new here, also a novice programmer, and not really familiar with PHP. I
I've recently started learning Python (long time Java programmer here) and currently in the
My colleague here argues that new programmers must learn ASP first, before they learn

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.