UC3M

Telematic/Audiovisual Syst./Communication Syst. Engineering

Systems Architecture

September 2017 - January 2018

9.8.13.  Read a known number of integers from a file

Resources

  • Section 3, 4 and 5 from Reading and writing with files

  • File fread_fixed_integers.c stored in the sub-folder fread_fixed in your shared folder.

  • Data files in binary format in the sub-folder fread_fixed in your shared folder.

Work Plan

  1. Write a program in the file fread_fixed_integers.c stored in the directory fread_fixed in the shared folder, that implements the following operations:

    1. Check the program is started with a single argument. If that is not the case, print a message and terminate.

    2. Open the file using as name the argument given to the program. If the operation fails, notify with a message and terminate the execution.

    3. Read from the file a maximum of 10 integers and store them in an array of size 10. The program must execute with any number of integers stored (from 0 to 10). If the read operation fails, notify with a message. Otherwise, prints out the numbers on the screen.

    4. Close the file and if the operation produces an error, notify it with a message on the screen.

  2. Check the program with the files fich_0_enteros (empty file), fich_07_enteros (file with 7 integers) y fich_10_enteros (file with 10 integers) that you may find in the shared folder.

  3. Upload the program to the folder fread_fixed in your workspace in Subversion.