Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. fwrite error???

fwrite error???

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    will1383
    wrote on last edited by
    #1

    Why would this: fwrite(dataPtr,sizeof(unsigned char),(sizeof(unsigned char)*datalength),filePtr); ALWAYS return 0 byte written :confused: I can open the file ok using filePtr = fopen (DataFile,"wb"); but whenever I try to write the data down it fails. Anyideas? Thanks!

    L M 2 Replies Last reply
    0
    • W will1383

      Why would this: fwrite(dataPtr,sizeof(unsigned char),(sizeof(unsigned char)*datalength),filePtr); ALWAYS return 0 byte written :confused: I can open the file ok using filePtr = fopen (DataFile,"wb"); but whenever I try to write the data down it fails. Anyideas? Thanks!

      L Offline
      L Offline
      Led 0
      wrote on last edited by
      #2

      are you sure your dataPtr is not NULL ? (or 0 - whichever your prefer :) )

      W 1 Reply Last reply
      0
      • L Led 0

        are you sure your dataPtr is not NULL ? (or 0 - whichever your prefer :) )

        W Offline
        W Offline
        will1383
        wrote on last edited by
        #3

        lol I just checked that and it seems my data pointer is not pointing to the right place. LOL. fix that and then try again. Thanks. I might be back. :-\

        W 1 Reply Last reply
        0
        • W will1383

          lol I just checked that and it seems my data pointer is not pointing to the right place. LOL. fix that and then try again. Thanks. I might be back. :-\

          W Offline
          W Offline
          will1383
          wrote on last edited by
          #4

          ok pointers are all correct now, data is where I need it to be. But still, no data being written when calling the fwrite. :~

          N 1 Reply Last reply
          0
          • W will1383

            ok pointers are all correct now, data is where I need it to be. But still, no data being written when calling the fwrite. :~

            N Offline
            N Offline
            Neville Franks
            wrote on last edited by
            #5

            Did the file open succeed? If you look at the data buffer in the debugger is it what you expect? What does errno tell you? Why aren't you checking what fopen() and fwrite() return. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com

            1 Reply Last reply
            0
            • W will1383

              Why would this: fwrite(dataPtr,sizeof(unsigned char),(sizeof(unsigned char)*datalength),filePtr); ALWAYS return 0 byte written :confused: I can open the file ok using filePtr = fopen (DataFile,"wb"); but whenever I try to write the data down it fails. Anyideas? Thanks!

              M Offline
              M Offline
              Mustafa Demirhan
              wrote on last edited by
              #6

              Firstly, your code should be like this: fwrite(dataPtr, sizeof(unsigned char), datalength, filePtr); It does not make any difference in case of a char, but if you use integers for example, your code will try to write 4x4xdatalength = 16xdatalength bytes of data, instead of writing 4xdatalength bytes. Anyway, apart from that be sure to check the datalength. Check out whether it is 0 or not. If it still does not work, add the following line after writing to the file: fflush (filePtr); Mustafa Demirhan http://www.macroangel.com Sonork ID 100.9935:zoltrix

              They say I'm lazy but it takes all my time

              W 1 Reply Last reply
              0
              • M Mustafa Demirhan

                Firstly, your code should be like this: fwrite(dataPtr, sizeof(unsigned char), datalength, filePtr); It does not make any difference in case of a char, but if you use integers for example, your code will try to write 4x4xdatalength = 16xdatalength bytes of data, instead of writing 4xdatalength bytes. Anyway, apart from that be sure to check the datalength. Check out whether it is 0 or not. If it still does not work, add the following line after writing to the file: fflush (filePtr); Mustafa Demirhan http://www.macroangel.com Sonork ID 100.9935:zoltrix

                They say I'm lazy but it takes all my time

                W Offline
                W Offline
                will1383
                wrote on last edited by
                #7

                Ok, I did finally find it. Turned out that my global datasize number was being clobbered all the time, aka ending in a data size of 0 to be written. Thanks for all of your help! I REALLY appreciate it! Woo HOO!! Dan

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups