Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Track file handle with int (http://www.go4expert.com/forums/track-file-handle-int-t2647/)

David_ 23Jan2007 04:18

Track file handle with int
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)

hide 25Jan2007 10:36

Re: Track file handle with int
fopen returns FILE *, the address of the FILE struct. I think that's what you're looking for.

DaWei 25Jan2007 19:41

Re: Track file handle with int
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.

All times are GMT +5.5. The time now is 22:47.