Browsing all articles tagged with fdopen() Archives - Share Programming Tips

Convert file descriptor to file pointer | Convert file pointer to file descriptor in Linux by C programming

 If you all ready know the difference between file descriptor and file pointer then good otherwise please read this post

Whats is difference between file descriptor and file pointer?



File descriptor to file pointer :

for converting file descriptor to file pointer in linux fdopen() function is used

#include <stdio.h
FILE *fdopen(int fildes, const char *mode);

fildes is file descriptor

mode is the character value which indicate the mode of file operation (same as we use in fopen() function)

Example :

#include <stdio .h>
#include <fcntl .h>
int main(){
int fd;
FILE *fp;
fd = open("shareprogrammingtips.txt",O_WRONLY | O_CREAT | O_TRUNC);
   printf("open call fail");
   return -1;
fprintf(fp,"we got file pointer fp bu using File descriptor fd");
return 0;

read more

Follow us on Twitter! Follow us on Twitter!

Search in this website

our sponsors

Find us on Facebook

Find us on stackoverflow


Tell us who you are

View Results

Loading ... Loading ...

My Bookmarks

Sponsers Link