using fprintf() to store data into a file
-
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
-
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
-
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
-
would i do:
FILE *filename; ULONG *buffer = NULL; buffer = new ULONG [10000]; ... fwrite(buffer, sizeof(ULONG), 10000, fileName); ... delete [] buffer;
Thanks.Kitty5
-
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
-
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
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
-
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