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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:31:48+00:00 2026-05-13T14:31:48+00:00

in the example: #include <stdio.h> main() { long nc; nc = 0; while (getchar()

  • 0

in the example:

#include <stdio.h>

main()
{
    long nc;

    nc = 0;
    while (getchar() != EOF)
        ++nc;
    printf("%ld\n", nc);
}

I don’t quite understand it. putchar() would put the character out, but why is it that after EOF it puts all the characters out, and where is it remembering all these characters? 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-13T14:31:49+00:00Added an answer on May 13, 2026 at 2:31 pm

    It’s called buffering and it’s done by the operating system. Usually it does line buffering where it just saves every character you put to it in memory, and then writes it all to the file when it encounters a line break. This saves on resources because file operations take much more time than other operations. So instead of doing output with every single character, it waits for a bunch of characters to collect in the buffer and writes them out all in one go.

    It’s just a clever maneuver done by the OS that you, the programmer, don’t need to worry about. Just throw your characters at it one by one and let the OS handle the rest in its own way.

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

Sidebar

Related Questions

For example: #include <stdio.h> #include <string> int main() { std::string* stuff(NULL); printf(allocating memory...); //line
I tried to compile this example: #include <stdio.h> #include <stdlib.h> #include <stddef.h> main(){ size_t
#include<math.h> #include<stdio.h> int main() { long i,j[100000],k,l,T,a,n[100000],c,sum=0,m; scanf(%ld\n, &T); for(c=1; c<=T; c++) { n[c]
#include stdafx.h #include stdio.h #include math.h int main() { float c; printf(Type c); scanf(%f,
/* strchr example */ #include <stdio.h> #include <string.h> int main () { char str[]
for example #include <stdio.h> #include <stdlib.h> #include <string.h> char substr[10][20]; int main() { substr[0]
I was just looking at this example from Deitel : #include <stdio.h> struct card
I was trying the following example of I/O ports from here . #include<stdio.h> #include<unistd.h>
Example: #include <iostream> using namespace std; int main() { wchar_t en[] = LHello; wchar_t
Very simple example: #include <string> #include <boost/program_options.hpp> namespace po = boost::program_options; int main(int argc,

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.