Originally Posted by
anduril462
I can't just give away code, but I can give you some hints. You need to know the name of the file (perhaps it's constant, or you read it as a command line parameter or from the user). Second, you need to open that file for reading. Use the fopen function and make sure you verify it was opened correctly (check for NULL), and if it fails, print an error (perror or strerr/errno are good for this) and exit. Store the file pointer fopen returns in a variable, say 'fp'. Then, instead of scanf(...), you simply use fscanf(fp, ...) to read the numbers from the file you opened. Make sure to close the file when you're done.
The nice thing about this is, you can easily make your program work with both file input and user/terminal input. If a file is specified, open that, and use that with fscanf. Otherwise, set your file pointer to stdin: fp = stdin; and continue using fscanf(fp, ...).
EDIT: If you chose to support terminal and file input, you may want to disable printing the prompts if you're reading from a file.