fwrite() in VC++6.0

W

Weichao Wang

Hi all,
I use the following code in a test program to test the use of fwrite(). But
the program just runs to the fwrite() and throws the error "Unhandled
exception in test.exe(MSVCRTD.DLL): 0xC00000005: Access Violation". I've
tested with or without the cast (const void*). But it makes no difference.
Can you give me tips on how to use fwrite()? many thanks in advance!

FILE *f = fopen("test.dat", "wb");
if (!f)
return;
short s = 23456;
long lo = 123456789;
fwrite((const void*)s, sizeof(short), 1, f);
fwrite((const void*)lo, sizeof(long), 1, f);
fclose(f);
 
P

Pavel A.

fwrite((const void*)&s, sizeof(short), 1, f);
fwrite((const void*)&lo, sizeof(long), 1, f);

--pa
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top