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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:13:11+00:00 2026-05-28T19:13:11+00:00

char yes_no = ‘z’; int i = 0; while ( ( yes_no != ‘y’

  • 0
            char yes_no = 'z';
            int i = 0;
            while ( ( yes_no != 'y' ) && ( yes_no != 'n')  )
            {
                read( 0, &yes_no, 1 );
                printf("%dA file already exists at your write location. Over    write? (y/n)\n", i++);
            }

Output looks like this:

0A file already exists at your write location. Overwrite? (y/n)
1A file already exists at your write location. Overwrite? (y/n)
a
2A file already exists at your write location. Overwrite? (y/n)
3A file already exists at your write location. Overwrite? (y/n)

…etc.

Why would it go through the loop twice instead of waiting for user input every time?

  • 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-28T19:13:12+00:00Added an answer on May 28, 2026 at 7:13 pm

    When you enter one letter and hit enter it puts 'a\n' into the stream. By reading 1 byte out of that you’re still left with '\n' in the stream, thus next time you call read(), it reads the '\n' instead of blocking and waiting for user input. You need to discard the '\n' that’s left in the stream.

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

Sidebar

Related Questions

I have this C++ file: #include <iostream> int main(int argc, char *argv[]) { std::cout
char *values = 3 1 4 15; vector<int> array; I want to populate the
char c='c'; int i=10; double d =50; long l=30; String s=Goodbye; Are these statement
{ char *a, *b; printf(%lx\n,(b-a)); } Usually works, in fact, I can't imagine it
char label[8] = abcdefgh; char arr[7] = abcdefg; printf(%s\n,label); printf(%s,arr); ====output========== abcdefgh abcdefgÅ Why
How does the following code work? typedef char (&yes)[1]; typedef char (&no)[2]; template <typename
int main (int argc, char* argv[]) { QApplication app(argc, argv); QTextStream cout(stdout, QIODevice::WriteOnly); //
#include <QtGui> int main (int argc, char* argv[]) { QApplication app(argc, argv); QTextStream cout(stdout,
char buf[BUF_LEN]_attribute_((aligned(4))); ssize_t len, i = 0; /* read BUF_LEN bytes' worth of events
Can the application use set same char in the XON and XOFF? If yes,

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.