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


int main()
{
   char str1[10], str2[10], str3[10];
   int year;
   FILE * fp;

   /*creates a file called file.txt and points fp to it*/
   fp = fopen ("file.txt", "w+");

   /*writes a string to the file pointed to by fp -- When 
    *fputs finishes the pointer is at the end of the file*/
   fputs("We are in 2012", fp);
   
   /*moves the pointer fp to the beginning of the file that 
    *string is pointing*/
   rewind(fp);

   /*remember -- we discussed that scanf cans until it finds 
    *a space, a tab, or end of file -- fscanf does the same
    *the fp increments until it finds a space, tab or eof*/
   fscanf(fp, "%s %s %s %d", str1, str2, str3, &year);
   
   printf("Read String1 |%s|\n", str1 );
   printf("Read String2 |%s|\n", str2 );
   printf("Read String3 |%s|\n", str3 );
   printf("Read Integer |%d|\n", year );

   /*When you open a file pointer you must call close fclose*/
   fclose(fp);
   
   return(0);
}