Question: Beginner C Programming. Need assistance. Need to accept input from stdin a file of data. Cannot open a file directly, but needs to read from

Beginner C Programming. Need assistance. 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".

Program is tested by piping it to a test file with something like this:

./tablecrypt

My issue is I'm having trouble actually rotating the table and swapping the bits on the suggested array.

Output the original 16 bytes as well as the newline character

For each byte of the rest of the data, encrypt the byte and print it, then after each byte rotate the table left as shown above.

Repeat this byte by byte until you encounter the end of the file.

You must use the following functions for this assignment:

o main in charge of running the show.

o rotate it takes one parameter, the 4x4 table, and rotates it 90 degrees left. It is a void function.

o encrypt it takes two parameters, the character to encrypt and the table. It returns a char as the result

Here is where I am at so far. Let me know what I can do to get this running.

#include

char grid[4][4];

int row = 0, col = 0;

int x, y;

char c;

void main() {

// Read the first Character

c = getchar();

// Validate the Character read by getchar() function ,terminates if user hit enter

while(c != ' ' ){

// Create Row entries

for(row =0 ;row<4;row++)

{ // Create column entries for above row.

for(col=0;col<4 && c != ' ';col++)

{

if(!isspace(c))

{ // Write record in Array

grid[row][col] = c;

}

c = getchar();

}

}

}

// Display the Records

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

{

for(y=0;y<4;y++)

{

putchar(grid[x][y]);

}

//putchar(' ');

}

}

void rotate(char grid[][]) {

/*

int i = 0, j = 0;

for(i=0;i<4;i++){

int k = 2;//k = (number of columns in the new array arr1 - 1)

for(j=0;j<3;j++){

arr1[i][j]=arr[k][i];

k--;

}

}

int l, m;

for(l=0;l<4;l++){

for(m=0;m<3;m++){

*/

}

void encrypt() {

//x = ((x & 0xf) << 4) | ((x & 0xf0) >> 4); ???

}

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!