reading and writing structures to pipes

This is a discussion on reading and writing structures to pipes within the Linux Programming forums, part of the Platform Specific Boards category; hello can any body help me reading and writing structures to files any sort of help is welcomed plz...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-05-2009, 02: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, 10: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, 12:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21