Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ 3.0r4 - <b>read</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
read

Usage

   #include <io.h>
   int read(unsigned fd,void *buffer,size_t len);

Description

   The system call read gets the next block of characters from the file
   associated with the file descriptor fd. The number of bytes read into the
   buffer is specified with the len parameter. The transfer is untranslated.

Example 

   #include <stdio.h>
   #include <stdlib.h>
   #include <dos.h>
   #include <io.h>
   #include <stdlib.h>

   #define BYTECOUNT 255

   int main()
   {
       char *buffer;
       int fd,numread,count;
       if((fd = open("file.dat",O_RDONLY)) == -1)
           {

               perror("open failed on file file.dat");
               exit(EXIT_FAILURE);
           }
       buffer = malloc(BYTECOUNT+1);
       for(count = 0;count <  BYTECOUNT;count++)
           buffer[count] = '\0';
       numread = read(fd,buffer,BYTECOUNT);
       printf("\nNumber of characters read %d\n",numread);
       close(fd);
       free(buffer);
       return EXIT_SUCCESS;
   }

Return Value

   Returns the number of characters actually read, which may be less than
   length if end-of-file was encountered. If a read error occurs, then a -1
   is returned and errno is set.

See Also

   fread, open, write



See Also: fread open write

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson