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

Need help with my C programing exersise. My program is currently reading input u

ID: 3594420 • Letter: N

Question

Need help with my C programing exersise. My program is currently reading input using getchar and reading a file that contains letters such as:

ABCDEF

YYYYYY

ZZZZZZZ

and I got my main to read in the "ABCDEF" into a table, but now I'm having issues reading in the rest of it so that I read "YYYYYY and ZZZZZZZ" and put that into an array that will be called into another method taking in the table I created from "ABCDEF". I need help setting up my new method that will put the rest of the data read so the "YYYYYY and ZZZZZZZ" so that I can compare my table and this new method to change value of my table if a certain condition is met, such as if A, swap bits, etc.

What I have:

#include <stdio.h>

void table(char[8]);

//I think i should have another prototype for my other method

int main(void)

{

int numberValue = 0;

char ch;

char table [8] ;

int x;

while ((ch = getchat()) != EOF)

{

if (numberValue < 8)

table[x] = ch;

x++
}

}

char table (char table [8] )

{

//will be printing the array table and passing it to check with last method

}

char lastMethod (char table[8], //should take in the last data read which will contain the Y's and Z's)

{

//will take in both tables and swap values here

//then print out the new values to screen

}

Explanation / Answer

You can first get table1 in an array named currentTable. Then read subsequent table in a separate array named lastTable inside the main method. Now, pass both these tables to lastMethod, this method will check whether to replace(or do some other operations) contents of currentTable with lastTable based on some condition.

Below is possbile implementation of lastMethod function and printTable function

/*prints the contents of a any table array on screen*/

void printTable(char table[8]) {

int i = 0;

for (i = 0; i < 8; i++)

printf("%c", table[i]);

printf(" ");

}

/*compares last read table with current table, and decides whether to swap current table with last table*/

void lastMethod(char currTable[8], char lastTable[8]) {

/*lets say if random value is 1 we replace contents of current table with last table other wise ignore*/

int i, r = 0;

r = rand() % 2;

if (r == 1) {

/*

for (i = 0; i < 8; i++)

currTable[i] = lastTable[i];

}

/*now prints the current table on screen*/

printTable(currTable);

}