Thread: reading and writing structures to pipes

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    14

    reading and writing structures to pipes

    hello
    can any body help me reading and writing structures to files
    any sort of help is welcomed
    plz
    /*****
    One can't let go and still win
    ******/

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    So what have you actually tried to do so far?
    You know about fread() and fwrite()?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    14

    fread

    according to the man page of fread
    size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);

    size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);

    DESCRIPTION
    The function fread reads nmemb elements of data, each size bytes long, from the stream pointed to by stream, storing them at the location given by ptr.
    The function fwrite writes nmemb elements of data, each size bytes long, to the stream pointed to by stream, obtaining them from the location given by ptr.

    now the stream interface both in the fread and fwrite is a file pointer so can i use it for fifos

    let us suppose that we have a custom structure
    struct temp;
    now i want to read data from a fifo fifo1 and write it in the temp structure
    how to do it
    /*****
    One can't let go and still win
    ******/

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    So you tried to read the manual basically

    How about
    FILE *fp = fopen( "myfifio", "w" );
    fwrite ( &temp, sizeof(temp), 1, fp );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-05-2009, 03:14 AM
  2. Pipe: writing and reading.
    By apacz in forum C Programming
    Replies: 0
    Last Post: 06-07-2006, 11:12 AM
  3. file writing and reading
    By Micko in forum C Programming
    Replies: 8
    Last Post: 01-13-2004, 11:18 AM
  4. writing linked structures
    By chrismiceli in forum C Programming
    Replies: 12
    Last Post: 07-06-2003, 01:14 AM
  5. reading structures from a file
    By bishopcl in forum C Programming
    Replies: 3
    Last Post: 02-07-2003, 01:01 AM