But the file.txt is containing junk values when i open it . Please let
me know what is wrong in my program.
with stdio.h included, I am getting the output you expected.
80000 40000 12345
80000 40000 12345
Your issue is already addressed. Your code appears to be broken in
more than one ways but the issue of seeing junk is that you are using
a text editor to analyze the file. Use a binary/hexadecimal editor and
you can check that you are getting the right values and some junk
because of your 3 in fwrite. (If you haven't used any binary/hex
editor, it will be all greek and latin with all the endian-ness and
stuff to worry about)
My compiler warns about your typedef:
bin.c:10: warning: useless storage class specifier in empty
declaration
Using a static code checker can let you know other issues which you
are ignoring ( not checking the return value for fopen, fread, fwrite
etc). In my case, lint has got this to say.
Splint 3.1.1 --- 19 Jul 2006
bin.c: (in function main)
bin.c:25:28: Possibly null storage fp passed as non-null param:
fwrite (..., fp)
A possibly null pointer is passed as a parameter corresponding to a
formal
parameter with no /*@null@*/ annotation. If NULL may be used for
this
parameter, add a /*@null@*/ annotation to the function parameter
declaration.
(Use -nullpass to inhibit warning)
bin.c:24:8: Storage fp may become null
bin.c:25:3: Return value (type size_t) ignored: fwrite(&A, sizeo...
Result returned by function call is not used. If this is intended,
can cast
result to (void) to eliminate message. (Use -retvalother to inhibit
warning)
bin.c:26:3: Return value (type int) ignored: fclose(fp)
Result returned by function call is not used. If this is intended,
can cast
result to (void) to eliminate message. (Use -retvalint to inhibit
warning)
bin.c:28:27: Possibly null storage fp passed as non-null param: fread
(..., fp)
bin.c:27:8: Storage fp may become null
bin.c:28:3: Return value (type size_t) ignored: fread(&B, sizeof...
bin.c:29:3: Return value (type int) ignored: fclose(fp)
lint is not related to the language C, but the output I have posted is
related to your C problem.