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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:05:18+00:00 2026-05-25T14:05:18+00:00

I have a piece of C code where I try to write a buffer

  • 0

I have a piece of C code where I try to write a buffer into an opened output file.I am getting a segmentation fault when I try to run the code.

if (fwrite(header, record_size, 1, uOutfile) != 1)
{
    return 0;
}

The header is a properly populated and I am able to print out the contents of the header.the size of the buffer header is definitely greater than the record_size.Is there anything else worth checking.?Any other reason where fwrite can cause a segfault.Gdbing the problem gave the following output

0x00007ffff6b7d66d in _IO_fwrite (buf=0x726d60, size=16, count=1, fp=0x738820) at iofwrite.c:43
43  iofwrite.c: No such file or directory.
    in iofwrite.c

it seems to suggest that the output file has not been created.how ever and ls -l on my directory shows the output file of size 0 bytes.

I would greatly appreciate if someone could throw some light on the problem.

EDIT: Code that opens the file:

outfd = open(out, O_RDWR|O_CREAT|O_TRUNC|O_LARGEFILE, 0664);
if (outfd == -1) {
    dagutil_panic("Could not open %s for writing.\n", out);
}
uOutfile = fdopen(outfd, "w");
  • 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-25T14:05:18+00:00Added an answer on May 25, 2026 at 2:05 pm

    I don’t think there’s enough here to know for sure what your problems are, but here are some thoughts:

    • Show us the code involving your FILE * (uOutFile) and your buffer (header) — we can then see if you’re borking memory somewhere between.
    • Run your code through valgrind: You’re getting a segfault, so it could probably catch what you’re doing wrong.
    • In gdb, examine the contents of both header and uOutFile (not just the pointer, but the pointed-to-memory.) (You’ll have to use some smarts to figure out if uOutFile looks right, but you should be able to up-or-down determine if header is correct.)

    To add to this: my general debug strategy when I get segfaults is:

    1. gdb‘s backtrace. Tells me where the segfault happened. Usually, this is enough to uncover the dumb thing I did.
    2. Look at the pointers in the vincinity of the crash. Is the pointer correct, and is the pointed-to data correct? (esp. if you see something strange like 0xdeadbeef)
    3. Valgrind Valgrind Valgrind

    (2 & 3 are in no particular order.)

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

Sidebar

Related Questions

I have the following piece of code to write data to an XML file.
I have the following piece of code: try{ SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp
Let's say you have a piece of code like: resource = allocateResource(); try {
I have the following piece of code try { if (!bDebug) smtp.Send(m); } catch
we have a piece of code which generates a zip file on our system.
I have this piece of code: <script language=javascript type=text/jscript> document.write(<img src='http://dm.leadgenesys.com/jpgp.lgt?en=P.........TP_Q=&amp;ur=' + escape(document.referrer) +
I have a Ria service to call logic code. I want to write try
I have this piece of code (summarized)... AnsiString working(AnsiString format,...) { va_list argptr; AnsiString
I have a piece of code looking like this : TAxis *axis = 0;
I have a piece of code here that i really could use some help

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.