Thread: Another binary file question

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    2

    Another binary file question

    I followed how to to write a binary file from this webpage:
    http://www.howstuffworks.com/c17.htm

    Mine is slightly different but basically the same thing. Anyways, when I do mine and it goes through the loop the second time I get a "segmentation fault". Do you guys have any idea why? If needed I'll copy some of the code but it's really very similar to the one from the webpage (just look at the writing the file part, specifically the loop with r.x=i)

    Thanks for any help.

  2. #2
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    Yeah, post some code.

  3. #3
    Registered User alex's Avatar
    Join Date
    Sep 2001
    Posts
    132
    I have not tried the code you link to, but it seems to me that you could run into trouble if you run it on an operating system that has differences in handling of text-files and binary files (such as dos, windows, macos and some others...). On POSIX-compliant os'es, there is no such difference. Try to open the files as binary files by adding a "b" to the mode argument of fopen:

    Code:
    fopen(..., "w") -> fopen(..., "wb")
    fopen(..., "r") -> fopen(..., "rb")
    fopen(..., "r+") -> fopen(..., "rb+")
    good luck,
    alex

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    If you could post some compilable code the exhibits the problem it would be easier to determine the cause. What you posted looks fine and my crystal ball has been decomissioned.

    -Prelude
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Jul 2002
    Posts
    2
    I'm programming in a Sun Solaris environment.

    Anyways, I don't think i can post all of the code. I'm interning at a place and security is pretty high with everything. Also the code is kind of long to paste here. Well thanks for the help anyways.

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I'm interning at a place and security is pretty high with everything.
    Understandable, my workplace is the same way.

    >Also the code is kind of long to paste here.
    I didn't ask you to post it all, just a bare bones program that compiles and still has the same problem. A little toy program for instance.

    Unfortunately, if you aren't capable of posting any useful code to us then it's up to you to step through your code and find the problem yourself through debugging techniques.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. File I/O Binary Question...
    By C+noob in forum C++ Programming
    Replies: 11
    Last Post: 07-11-2005, 07:51 AM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM