I use a array to represent a table and I want to use "getchar" to update the value in the table.
Original table: 0 0 0 0 Input table: 1 0 Output table: 1 0 0 0
0 0 0 0 1 1 1 1 0 0
0 0 0 0 0 0 0 0
struct dimension {// represent the number of row and number of col of a table
int num_row;
int num_col;
};
void set_value(int t[],
const struct dimension *dim,
const int row,
const int col,
const int v) {
t[row*dim->num_col+col] = v;
}//update the value in a table
void update (int t[],
const struct dimension *table_dim,
struct dimension *input_dim) {
for (int k=0; k<(input_dim->num_row); k++){
for (int l=0; l<(input_dim->num_col); l++){
array[l] = getchar();
table_set_entry(array, input_dim, 0, 0,array[l]);
if (array[l] == '\n') break;
}
}
}
int main(void) {
int o[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
const struct dimension a = {3,4};
struct dimension in_dim = { 4, 5 };
update(o,a,in_dim);
}
My idea is that I should create a table and set all the value to be zero for input table first. Then change it base on the getchar(). At last, update the original table. However, I dont know how to use getchar to change the value. Can someone help me out? If there is something makes you confuse, leave a comment. Thank in advance. :)