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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:15:28+00:00 2026-06-07T00:15:28+00:00

When I run the first code and press ctrl-c immediately there will be no

  • 0

When I run the first code and press ctrl-c immediately there will be no 45 written out to the file. But when I run the second code, I do get 45.

I couldn’t come to the reason why this behavior happens in the below code? If stdout is line buffered shouldn’t output come after I enter a character? What am I missing?

First code:

#include<stdio.h>
#include<stdlib.h>
int main()
{
   FILE *fp=stdout;
   fp=fopen("myfile","w");
   fprintf(fp,"%d",45);
   getchar();
  // return 0;

}

Second code:

#include<stdio.h>
#include<stdlib.h>
int main()
{
   FILE *fp=stdout;
   fprintf(fp,"%d",45);
   getchar();
  // return 0;

}

PS: I’m using GCC and the platform is Linux.

  • 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-07T00:15:30+00:00Added an answer on June 7, 2026 at 12:15 am

    Whats causing confusion is getchar(), seems like when it is called it is flushing stdout.

    If you replace getchar() with something like sleep(10) then you 45 won’t be printed.

    #include<stdio.h>
    #include<unistd.h>
    #include<stdlib.h>
    int main()
    {
       FILE *fp=stdout;
       //fp=fopen("myfile","w");
       fprintf(fp,"%d",45);
       sleep(10);
       //getchar();
      // return 0;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the following code to run (it's from the Heads First
when I run this code for the first time <?php session_start(); echo SID; ?>
When I run the following code, it only seems to be downloading the first
I have the following code. When I press my save button, three requiredfieldvalidators run
I have a perl code to compare 2 strings First string I get from
I can't figure out how to run code from different View Controller 's .
I tried to run this code: #define ROW_CNT 8; #define COLUMN_CNT 24; #define FIRST_COLUMN
Actually I am developing one application in that when application run first time it
I have two jQuery functions. The first one below I want to run first,
When I first run my program and type some text in the richtextbox, if

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.