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. using fprintf() to store data into a file

using fprintf() to store data into a file

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
8 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.
  • K Offline
    K Offline
    kitty5
    wrote on last edited by
    #1

    I have: ULONG *buffer = NULL; I do: buffer = new ULONG[10000]; ... create a file, etc. fprintf( fpwrite, buffer ); ... delete [] buffer; the problem is: fprintf(FILE *fptr, const char* cptr). so, fprintf doesn't take a ULONG pointer as a parameter. would it be safe for me to: fprintf( fpwrite, (char *) buffer ); Will I lose data by doing this? size of char is only 1 byte and size of ULONG is 4 bytes in my system... Also, how can one limit the size of a file being created and appended? Thanks.

    Kitty5

    N B D 3 Replies Last reply
    0
    • K kitty5

      I have: ULONG *buffer = NULL; I do: buffer = new ULONG[10000]; ... create a file, etc. fprintf( fpwrite, buffer ); ... delete [] buffer; the problem is: fprintf(FILE *fptr, const char* cptr). so, fprintf doesn't take a ULONG pointer as a parameter. would it be safe for me to: fprintf( fpwrite, (char *) buffer ); Will I lose data by doing this? size of char is only 1 byte and size of ULONG is 4 bytes in my system... Also, how can one limit the size of a file being created and appended? Thanks.

      Kitty5

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      Why don't u use fwrite(. It can satisfy all the above requirments.

      nave

      K 1 Reply Last reply
      0
      • N Naveen

        Why don't u use fwrite(. It can satisfy all the above requirments.

        nave

        K Offline
        K Offline
        kitty5
        wrote on last edited by
        #3

        would i do: FILE *filename; ULONG *buffer = NULL; buffer = new ULONG [10000]; ... fwrite(buffer, sizeof(ULONG), 10000, fileName); ... delete [] buffer; Thanks.

        Kitty5

        N 1 Reply Last reply
        0
        • K kitty5

          I have: ULONG *buffer = NULL; I do: buffer = new ULONG[10000]; ... create a file, etc. fprintf( fpwrite, buffer ); ... delete [] buffer; the problem is: fprintf(FILE *fptr, const char* cptr). so, fprintf doesn't take a ULONG pointer as a parameter. would it be safe for me to: fprintf( fpwrite, (char *) buffer ); Will I lose data by doing this? size of char is only 1 byte and size of ULONG is 4 bytes in my system... Also, how can one limit the size of a file being created and appended? Thanks.

          Kitty5

          B Offline
          B Offline
          bob16972
          wrote on last edited by
          #4

          This sounds like a homework assignment. We don't do homework

          K D 2 Replies Last reply
          0
          • K kitty5

            would i do: FILE *filename; ULONG *buffer = NULL; buffer = new ULONG [10000]; ... fwrite(buffer, sizeof(ULONG), 10000, fileName); ... delete [] buffer; Thanks.

            Kitty5

            N Offline
            N Offline
            Naveen
            wrote on last edited by
            #5

            yes..:)

            nave

            1 Reply Last reply
            0
            • B bob16972

              This sounds like a homework assignment. We don't do homework

              K Offline
              K Offline
              kitty5
              wrote on last edited by
              #6

              Actually no... Thanks though. I've been out of school for quite sometime. I'm just clearing things up since some of these functions I've never used. Just because other ppl are more adept at programming doesn't mean the the ones that are teaching themselves to be better at it should be penalized or scoffed at. thanks for your help though.

              Kitty5

              -- modified at 8:55 Monday 24th July, 2006

              1 Reply Last reply
              0
              • K kitty5

                I have: ULONG *buffer = NULL; I do: buffer = new ULONG[10000]; ... create a file, etc. fprintf( fpwrite, buffer ); ... delete [] buffer; the problem is: fprintf(FILE *fptr, const char* cptr). so, fprintf doesn't take a ULONG pointer as a parameter. would it be safe for me to: fprintf( fpwrite, (char *) buffer ); Will I lose data by doing this? size of char is only 1 byte and size of ULONG is 4 bytes in my system... Also, how can one limit the size of a file being created and appended? Thanks.

                Kitty5

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                kitty5 wrote:

                fprintf( fpwrite, buffer );

                Should be:

                fprintf( fpwrite, "%lu", buffer[0]);
                fprintf( fpwrite, "%lu", buffer[1]);
                ...


                "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

                "Judge not by the eye but by the heart." - Native American Proverb

                1 Reply Last reply
                0
                • B bob16972

                  This sounds like a homework assignment. We don't do homework

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  bob16972 wrote:

                  This sounds like a homework assignment.

                  Not even remotely.


                  "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

                  "Judge not by the eye but by the heart." - Native American Proverb

                  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