C and C++ output calls

This is a discussion on C and C++ output calls within the C++ Programming forums, part of the General Programming Boards category; Hi everyone, I have a problems that I haven't came across before. I realise that what how I coded was ...

  1. #1
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257

    C and C++ output calls

    Hi everyone,

    I have a problems that I haven't came across before. I realise that what how I coded was not proper, but it should have worked and it did up till now.

    I used C print calls ( fprintf(), etc) to create a binary output file. This works fine on my workstation. Now, when I try to run the executable on a different workstation on the network (runs on Windows NT), I get error messages that the memory could not be read. On my comp in Debug mode I don't get any errors at all.

    I tryed switching to C++ earlier in the project but ran into a lot of trouble printing to a binary file; I need it in a particular format and need to control the bits that are written not only nubers and such; and with C++ the format was not recognised because there were extra bytes written.

    Is there a painless way to fix this? Otherwise If you could let me know how to print specific bytes from a long int, or just a byte in C++, please. I would prefer not to hcange the code for it will take a year and a half.

    Thanks.
    Everything is relative...

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    Try fread() and fwrite().
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    With fwrite() you can only print one variable at a time, or the same one multiple times, right? Can I print multiple variables in one fwrite call()?
    Everything is relative...

  4. #4
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    I figured out the problem.
    Thanks though.

    AS
    Everything is relative...

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21