Question: Beginner C Programming. Need assistance filling a 4x4 2 Dimensional array using getchar(). Need to accept input from stdin a file of data. Cannot open

Beginner C Programming. Need assistance filling a 4x4 2 Dimensional array using getchar(). Need to accept input from "stdin" a file of data. Cannot open a file directly, but needs to read from standard input. The data within the file consists of a string of 16 characters, followed by a newline character. Everything needs to be read with "getchar", and after the data has been stored in the array, print the 16 characters with "putchar".

For an example, the first file has "SNSSNSNSSNNSSNNS as the input data.

Am I on the right track?

#include

char grid[4][4];

int row = 0, col = 0;

int x, y;

char c;

void main() {

for(x = 0; x < 17; x++) {

while ((c = getchar()) != ' ') {

if (!isspace(c)){

grid[row][col++] = c; }

}

row++

}

for(x = 0; x < 17; x++)

{

putchar( grid[x] );

}

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!