Thread: close and fclose

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    21

    close and fclose

    I was curious as to what the difference is between a FILE * stream (which fclose closes) and an int fd (which close closes).

    And also, is there a problem with opening a pipe using fopen, I am currently using open(because that's what all the tutorials used) but they never said it was required, I would like to use io operators that work on FILE * streams, but I'm dealing with two different data types, are there any other files where it makes a difference whether you open them using fopen and work with a FILE * stream or open them using open and work with an int fd?

    Thanks,
    Ian (:

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Use popen, as per this link, you should be able to tread a pipe as a standard stream. Additionally, you'll want to use the associated function, pclose.

    I don't have a really good description of FILE* versus 'int fp', other than one is set up in a more simplistic manner, while using 'open' is more low level reading (for example, you have to use 'read' instead of 'fread'. Socket programming in C is done this way also.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    21
    Thanks Quzah

    That explains it a bit more for me, although I did leave out one valuable piece of information, I am actually using named pipes(FIFO's) so I don't think it gets opened the same way as an unnamed pipe, because it's more like a file...

    What would you recommend I open it with?

    Thanks again,
    Ian (:

  4. #4
    Registered User alex's Avatar
    Join Date
    Sep 2001
    Posts
    132
    The function fdopen creates a FILE struct from your file descriptor. It should also work on pipes.
    fopen/fread/fwrite/fgets/fputs/fscanf/fprintf/fseek/ftell/fclose are high-level functions that possibly use buffering and block-reading strategies to speedup file processing more or less transparently to the programmer. (setbuf/setvbuf/setbuffer/setlinebuf are functions to specify the buffering strategy).
    open/fcntl/pipe/dup/dup2/creat/read/write/lseek/close are the low-level functions that interact directly with the os.

    alex

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I haven't used named pipes myself, but a quick search of google found the following link that may be of some help.

    Run '"named pipes" programming' through google and see what else you can turn up.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fclose slow
    By Rmantingh in forum C Programming
    Replies: 4
    Last Post: 04-08-2010, 11:01 AM
  2. One help with fclose();
    By sreeramu in forum C Programming
    Replies: 3
    Last Post: 12-03-2007, 02:47 AM
  3. Cant close file pointer
    By mbooka in forum C Programming
    Replies: 4
    Last Post: 04-06-2006, 03:30 AM
  4. fclose()
    By GanglyLamb in forum C Programming
    Replies: 4
    Last Post: 11-11-2002, 08:45 AM
  5. fclose problems
    By drakmantis25 in forum C Programming
    Replies: 2
    Last Post: 01-31-2002, 06:55 AM