Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programing Language: C How do you handle End of file so that you only take the f

ID: 3587389 • Letter: P

Question

Programing Language: C

How do you handle End of file so that you only take the first 4 charachters from the file and stores it into a 2D Array and then displays the remaining file input when running the command line. Example:

In the command line, input will contain the following:

ABCD

TTTTTTTTTTTTTTTTTTTT

0123456789101112131415

EXTRA

INPUT

So when running the program we should get the following:

(the first four charachters are stored into a 2D Array and the rest of the data in file is just printed out)

terminal:$ /Array

Explanation / Answer

#include <stdio.h>

int main()
{
char arr[2][2];
int i, j;
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
scanf("%c", &arr[i][j]);
}
}
  
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
printf("%c ", arr[i][j]);
}
printf(" ");
}
  
char c;
while ((c = getchar()) != EOF) {
printf("%c", c);
}

return 0;
}