what's difference between fd and fp?

This is a discussion on what's difference between fd and fp? within the C Programming forums, part of the General Programming Boards category; Hi. Just wondering what the main differences between a file pointer and a file
descriptor are.
I know that a ...

I'm not sure that is entirely correct. WIth access to stdio.h and hence the FILE structure, you also gain access to fileno() which will return a file descripter given a stream. So I'm pretty sure file descriptors exist as part of standard C (of course, their meaning/representation in the underlying file subsystem can vary depending on platform).

Edit: nm, you are correct, I double checked IEEE standards and it indeed tags fileno() as an extension to ISO C.

I'm not sure that is entirely correct. WIth access to stdio.h and hence the FILE structure, you also gain access to fileno() which will return a file descripter given a stream. So I'm pretty sure file descriptors exist as part of standard C (of course, their meaning/representation in the underlying file subsystem can vary depending on platform).

As brewbuck was saying, file descriptors are the Unix way of handling files.

For Windows, instead of a file descriptor, you receive a variable of a windows-specific type called a HANDLE, and you use that instead of a file descriptor.

The C standard library is written on Windows to use the Windows specific file handling routines. On Unix, it's written to use the Unix specific file handling routines. Even something as simple as printf() has to call specific functions to put its data to the console output. In Unix, it's write(). For Windows, it's WriteConsole() (or alternatively WriteFile(), I believe). Everything is O/S specific when it comes to input and output, and especially when dealing with files.

This is why you should use the standard C library when possible if you wish your code to compile on almost any given O/S. The benefit of this is that you don't have to be concerned with file descriptors or HANDLEs to files, and you especially don't have to worry about writing multiple different versions for every program to get them to compile on every O/S you wish to support

when we say file pointer then it means a pointer variable of FILE type.
which stores return value of "FILE *fopen(const char *path, const char *mode);"
And when we say file descriptor then it means a int type variable which will store return value of "int open(const char *pathname, int flags);"