1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Track file handle with int

Discussion in 'C' started by David_, Jan 22, 2007.

  1. David_

    David_ New Member

    Joined:
    Jan 22, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello.
    I need to return a "file handle" (this is C by the way... returned by fopen())
    I know fopen returns a FILE struct, but is it possible to use "IDs", ints, that "search" for that FILE struct?

    Similar to what winsock does... (That SOCKET returns an int number, which can then be used with the all socket functions)
     
  2. hide

    hide New Member

    Joined:
    Jan 25, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    fopen returns FILE *, the address of the FILE struct. I think that's what you're looking for.
     
  3. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    A file handle is an integer, a FILE is a struct (that varies somewhat between implementations). Use "int _fileno (FILE *stream);" to get the handle from the FILE *. There is no error return. Operation is undefined if stream doesn not represent an open file.
     

Share This Page