// This program opens a file and reads a specified number of integers
// from it, but it isn't complete. Add the necessary code, using the
// comments as a guide. Run the program (with the appropriate 'make'
// command), and compare your results with the data in the file
// referenced in the "prob6_test" target of the Makefile
// Your corrections will replace all the xxxxxxxx markers with real code.
// Hint: the number of x's is a clue;
// Set the number of integers to read from the file
#define NUMBER_PER_LINE 3
#include <stdio.h>
#include <stdlib.h> // For atoi()
int main(int argc, char* argv[])
{
// Part One of your task. Open the file named by the second command-line
// parameter; open the file in "read" mode.
FILE* inf = xxxxxxxxxxxxxxxxxxxx
if (!inf)
{
printf("Cannot open file %s\n", argv[1]);
return 1;
}
// Here are the integers it's trying to read, one per line
int n[NUMBER_PER_LINE];
fscanf(inf, "%d %d %d", &n[0], &n[1], &n[2]);
// Part Two of your task. You've read the date, now close the file
xxxxxxxxxxxx
// Part Three of your task; print out the integers you read above
// using an appropriate loop, one integer per line.
// print one integer in each line
for (int i = 1; i <= NUMBER_PER_LINE; i++)
{
xxxxxxxxxxxxxxxxxxxxx
}
return 0;
}