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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:50:27+00:00 2026-06-11T14:50:27+00:00

I believe my issue stems from the printf print buffer, but I know too

  • 0

I believe my issue stems from the printf print buffer, but I know too little about C or buffers to know how to handle this. I have a simple program written and it just prints a bunch of text (chars/strings) based on some if/else statements depending on the file that is input. If I call it from a Unix shell like so:

gcc -o myProgram myProgram.c
./myProgram fileName

It will print out correctly for only the first run. If i reiterate these steps and once again run the program, it prints out a bunch of “bash” commands in between the output printfs. Is there an easy way to debug or fix this issue? I’m very new to C, if you couldn’t tell, and I’m using this as part of a school assignment so I am trying to actually figure this out and understand this concept, such that I can then apply it back into my actual program assignment.

EDIT: This is a make-shift example to try to demo my issue
Note: The file inputted just contains text.

#include <stdio.h>
#include <stdlib.h>

struct S{
    char word[30];
}s;

int main(int argc, char ** argv)
{
    void print(struct S *s);
    int i; 
    FILE *f = fopen(argv[1], "rb");
    fseek(f, 0, SEEK_SET);
    fread(&s, sizeof(s), 1, f);
    print(&s);
    fclose(f);
}

void print(struct S *s)
{
    int i = 0;
    printf("Word: ");
    for(i = 0; i < 30; i++)
    {
        if(s->word[i] != '\0')
        {
            printf("%c", s->word[i]);
        }       
        else
        {
            break;
        }
    }
    printf("\n");
}
  • 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-11T14:50:28+00:00Added an answer on June 11, 2026 at 2:50 pm

    You can test this :

    Add the following line at the first line in the main() :

    setbuf( stdout , NULL );
    

    The outputs of a program are stored in a buffer and when you call printf they are extracted. the setbuf() method is used for handling that buffer. when You add setbuf(stdout , NULL), this tells the buffer that don’t store the outputs and directly send outputs of the program into the stdout.

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

Sidebar

Related Questions

This issue stems from an accounting package that spits out text-based reports with rows
This issue is specific to RestKit , but I believe the underlying issue is
My issue is I believe I've constructed the request correctly, but I am getting
At first glance this seems like a purely subjective/aesthetic issue, but I'd be interested
Ok this question stems from this question: wp7: App failing! Can not figure out
I believe I have a potential threading issue. I have a user control that
I believe I am having a memory issue using numpy arrays. The following code
I am having, what i believe is a minor issue. I am developing a
I believe I've set this up correctly. Can somebody see anything wrong with this
The issue is the results from local host are not matching up with the

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.