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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:49:09+00:00 2026-06-05T10:49:09+00:00

My program has to read just ONE character from the standard input, and so

  • 0

My program has to read just ONE character from the standard input, and so I use read(0, buffer, 1).
But if the user insert more than one single character, they remain in some buffer and when I call a read again they are still there.

So, how can I discard these characters?
I want that when I call a read again, the buffer is filled with the new character, not with the old ones.

An example:
I’ve a read(0, buffer, 1) and the user writes abcde. My buffer contains a (and it’s right), but then I call read(0, buffer, 1) again and I want the next character written by the user from now, and not the b written before.

  • 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-05T10:49:11+00:00Added an answer on June 5, 2026 at 10:49 am

    When your program wants to start reading characters, it must drain the buffer of existing characters and then wait to read the character.

    Otherwise, it will read the last character entered, not the last character entered after right now.

    Naturally, you do not need to do anything with the read characters; but, you do need to read them.

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

Sidebar

Related Questions

My program has two threads: Main execution thread that handles user input and queues
My program has one dialog and two sockets. Both sockets are derived from CAsyncSocket,
If a program has literally just deserialized an object (doesn't really matter how, but
There are many approaches, one could use create a Program and just call the
The data model in my program has a number of discrete states, but I
A program has the output set to 2 decimal place floats, one on each
I've never used Smalltalk, but I've read a lot about it and it has
My Perl program takes some text from a disk file as input, wraps it
I have a possibly long running program that currently has 4 processes, but could
I'm writing this little program in shell: #!/bin/bash #*************************************************************** # Synopsis: # Read from

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.