#include "stdio.h" #include "stdlib.h" int main (void) { FILE* pInFile; char szFilename [80]; char szWord [30]; /* assumes that words in the file are <30 chars */ /* open the file for input. */ printf ("filename? "); scanf ("%s", szFilename); /* "r" in the next line means "open for reading" */ pInFile = fopen (szFilename, "r"); if (!pInFile) { fprintf (stderr,"Can't open %s\n",szFilename); exit (-1); } /* read words from file and print to screen on separate lines */ /* fscanf returns the number of successfully filled arguments; here, 1 is good, while 0 or EOF happen if the file is at the end. */ while (fscanf (pInFile, "%s", szWord) == 1) printf ("%s\n", szWord); /* fclose closes a file */ fclose (pInFile); return 0; }