I just started learning programming languages and I want to make a character (point '*') in a table move.
This is my code
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main() {
int v;
int x = 50, y = 10;
int i, j;
char screen[80][25];
// declare and initialize table
for (i = 0; i < 80; i++)
for (j = 0; j < 25; j++)
screen[i][j] = ' ';
// coordinate system
for (i = 0; i < 80; i++) screen[i][12] = '-';
for (j = 0; j < 25; j++) screen[40][j] = '|';
// point, position
screen[x][y] = '*';
// print result
for (j = 0; j < 25; j++) {
for (i = 0; i < 80; i++)
printf("%c", screen[i][j]);
printf("\n");
}
}
This prints a table of size 80x25 and a coordinate system with a centre in (40,12). I set the position of the character '*' on coordinates (x,y). I defined x and y as 50 and 10.
Now I want to move my star by changing x and y. How do I change x and y (position of the star)? Maybe with scanf function? I tried to use scanf like this:
int v;
...
scanf("%d", &v);
if(v == 1)
{
y--;
}
but then everything (table, coordinate system and the character) disappeared. Please help.
Thanks.
Aucun commentaire:
Enregistrer un commentaire