#include /* a header needed for scanf function */ #include /* a header needed for FILE */ /* define the pointer for the input file globally */ FILE *input_file_pointer; void main(void) { /* variable to read in the words from the file */ char word[50]; /* no word above 50 characters */ printf("\n We will split the file parse.c into words"); printf("\n each word will be output to the screen delimited by ()\n"); printf("\n all words will be on the same line\n"); /* open input file n.b. no test for the case that filled does not exist */ input_file_pointer = fopen("parse.c", "r"); /* use while construction to use fscanf until an EOF is reached */ /* %s reads a string - a word and != means not equal */ /* do not place semicolon at the end of the line */ /* do not put & before word as it is an array */ while( fscanf( input_file_pointer, " %s", word)!=EOF) { printf(" (%s)", word); /* print word surrounded by brackets */ } /* end of while construction */ } /* end of main function */