#include <stdio.h>
#include <string.h>

#include <fcntl.h>

int main()
{
   int fd, len, buflen;
   char buf[100];

   strcpy (buf, "yaay I'm writing to a file!\n");

   // Create a file and write to it
   len = 0;
   buflen = strlen(buf);
   fd = open("foo.txt", O_RDWR | O_CREAT);
   do
   {
      len += write(fd, buf, buflen - len);
   } while(len < buflen);
   close(fd);

   memset(buf, 0, 100);    // zero out the buffer

   // Read from a file
   fd = open("file.txt", O_RDONLY);
   read(fd, buf, 100);
   printf("Read the following from the file..\n%s\n", buf);
   close(fd);

   return 0;
}