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++ Language Reference - read 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 length);

   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 length parameter. The  transfer  is
   untranslated(it is a direct call to MSDOS).

   Example
   #include <stdio.h>
   #include <stdlib.h>
   #include <dos.h>
   #include <io.h>
   #define BYTECOUNT 255
   main()
   {
   char *buffer;
   int fd,numread,count;
        if((fd = open("file.dat",O_RDONLY)) == -1)
        {
             perror("open failed on file file.dat");
             exit(1);
        }
        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 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

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