Beruflich Dokumente
Kultur Dokumente
1. Fill in the blanks in the program below so it prints the contents of the file whose name
is provided by the user.
#include <stdio.h>
int main ( ) {
char fileName[32];
int c;
FILE *inFile;
printf ("File name? ");
scanf("%31s", fileName);
_________________________ ;
if ( ____________________ ) {
fprintf ( _____________ , "File doesn't exist!\n");
exit (1);
};
while ( ____________________ ) { /* get a char if not done*/
fprintf ( _______________ ); /* print it */
}
return 0;
}
3. Fill in the blank in the code below so that it moves each element of the values array
to the immediately subsequent position in the array. The loop should discard the last
value in the array. Thus if the array contained the values 1, 2, 3, 4, and 5 before the
loop, it should contain the values 1, 1, 2, 3, and 4 after the loop.
int values[5];
...
for ( ____________________ ) {
values[k] = values[k-1];
}
4. Modify the definition of the values array in exercise 3 so that it also initializes the
array to contain the values 1, 2, 3, 4, 5.
5. Write a function HasZeroDiagonal that, given a 5-by-5 integer array, returns 1 if all
the elements on the main array diagonal are zero and returns 0 otherwise.