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

  • Home
  • SEARCH
  • 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 8123193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:05:50+00:00 2026-06-06T06:05:50+00:00

i was reading about streams and found out that we could control streams by

  • 0

i was reading about streams and found out that we could control streams by using setvbuf() function…it was written tat in line buffered mode stream sends the data to the file when a newline is encountered and in unbuffered there is no buffering…so i wrote the following code…

#include<stdio.h>


int main()
{

setvbuf(stdin, NULL, _IONBF, 40);
setvbuf(stdout, NULL, _IONBF, 40);
while(1)
{
char a[40];
int n;
n=fread(a, 1, 4, stdin);

if(n>0)
fwrite(a, 1, n, stdout);
}
return 0;
}

so i think that because these are unbuffered streams, input should be sent to stdout as soon as i write to the screen…but the program waited for me to press enter after writing each line and then only output appeared on the screen(as a result of fwrite)…my question is why the progam waited for enter(i.e. newline) when these were unbuffered streams…

  • 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-06T06:05:53+00:00Added an answer on June 6, 2026 at 6:05 am

    I believe this is due to how the shell in your environment works: the data you entered is not available on stdin until you hit enter, so the fread is blocking until it can read something from the stream

    Think how you would need to handle back-space and the like if the shell passed every character to the buffer

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

Sidebar

Related Questions

While I was reading the reference about fopen function, I found out that FOPEN_MAX
Reading about Delphi's Exit statement (see here for instance), I cannot ignore that writing
When reading about pipes in Advanced Programming in the UNIX Environment, I noticed that
I was reading about this scenario where making use of the C# using statement
I was reading here about problems in PHP when using include() or required() with
I was reading about sockets and found a nice exercise to try: a simple
I have been reading about streams in Java the past days. After reading quite
I have been reading about streams, but when I try and deviate from the
When I was reading this tutorial I noticed the following performance tip about using
Reading about the Dispose pattern , I see the documentation repeatedly refer to cleaning

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.