I want to be clear, yes this is a homework related question, and no I don't expect you to do my homework for me. I love coding and I'm just looking for advice.
Having said that, I'm a creating the Game of Life in C. Here is some code to show I've been working on this:
void create_area(void){
int table[24][80];
int i,j;
int xvalue=10,yvalue=10;
table[10][10] = 2;
/*for(j=0; j<24; j++){
for(i=0; i<80; i++){
table[j][i] = 1;
}
}*/
for(j=0; j<24; j++){
for(i=0; i<80; i++){
printf(" ",table[j][i]);
}
printf("\n");
}
/*if(xvalue=10){
if(yvalue=10){
printf("O", table[xvalue][yvalue]);
}
}*/
/*for(j=0; j<24; j++){
for(i=0; i<80; i++){
if(xvalue=0){
if(yvalue=0){
printf("O",table[xvalue][yvalue]);
}
}
}
}*/
}
My main method isn't shown here, but it takes care of finding the number of arguments and the argument strings and putting them into coordinates with two arrays that I make (an x_array and y_array). The method show above is basically create the grid in the terminal. The parameters for create_area is void for now (because I just want to test values to see if it works, which is why I have two int variables: xvalue and yvalue). But the idea is that create_area will take a x value and y value and initialize the character 'O' where the cell would begin. A lot of the code is commented out because I'm trying to figure stuff out.
My question: How do I insert a character within my 2d array so that it displays that character in a spot on the grid when looking at it in the terminal?
So far I created my 2d array, and used two for loops to go through it and print spaces. But I'm trying to figure out how to print a char for example at table[10][10]. I tried a few things, but the character won't display at the certain location, only at the bottom left of my screen. I think I'm missing something simple.
Any help would be appreciated.
printf? Do you sure that it outputs some visible characters? – Шах 6 hours ago=in C. It's harder to read and tackier when everything is crammed together. White space provides separation that makes things easier to assimilate. If you want to cut whitespace in a way that really helps, your formatting style is good, the way you brace things. Braces on new lines (some people take that to an extreme) entails too much scrolling to read the code. – clearlight 5 hours agoprintf(" ", table[j][i]);" this is a serious code issue and if you enable compiler warnings (gcc:-Wall -Werror -Wextra -pedantic-errors) you will find and fix many critical issues, and the code you write will be safer and standards compliant. – cat 4 hours ago