File input output 
Author Message
 File input output

i am writing a file which simulates a disk drive on UNIX.
i am trying to write info to a file (disk characteristics) and then read back
at a later time.
some of the info is originally integers and in order to write in UNIX you need
to use the write(int, const void *, int)
and read(int, void *, int)   (UNIX system calls)
to read and write, but i cannot figure out how to convert from integer to void
*(if needed) and convert back to use integer once again.
can anyone help me.

thank you



Sat, 24 Mar 2001 03:00:00 GMT  
 File input output

Quote:

> some of the info is originally integers and in order to write in UNIX you need
> to use the write(int, const void *, int)
> and read(int, void *, int)   (UNIX system calls)
> to read and write,

Hi ERICWEI,

Not necessarily. To write data to file in ANSI-C all you need is
"fread()" and "fwrite()". In fact the "read" and "write" functions
are not part of ANSI-C, which makes them pretty compiler specific.

Quote:
> but i cannot figure out how to convert from integer to void
> *(if needed) and convert back to use integer once again.

To write an integer to a binary file, you pass it's address to the
"fwrite()" function:
   fwrite( &myInteger, sizeof(int), 1, fp );

And similarely if you want to read one integer from a binary file
you give the address of the variable where the value is to
be stored:
   fread( &myInteger, sizeof(int), 1, fp );

Stephan
(initiator of the campaign against grumpiness in c.l.c)



Sat, 24 Mar 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. File Input/Output

2. input, output, input/output parameters?????

3. questions on file input and output

4. searching for high performance C-libraries for input-output and file-handling

5. file input and output

6. File Input and Output

7. A simple example of input/output to a file

8. process input-output files

9. A simple example of input/output to a file

10. ANSI C Run Time Erroe to output data to the output file

11. VC 5 TRACE output to a file instead of the output window

12. MFC CDC HTML Output (ala Meta File Output)

 

 
Powered by phpBB® Forum Software