1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#include <stdio.h>
enum
{ PIX_OFF = ' ', PIX_ON = '*' };
enum
{ NB_LIN = 24, NB_COL = 79 };
struct screen
{
char tab[NB_LIN][NB_COL];
int nb_lin;
int nb_col;
};
void pix_init (struct screen *this, int nb_lin, int nb_col)
{
if (this != NULL)
{
this->nb_lin = nb_lin;
this->nb_col = nb_col;
{
int lin;
for (lin = 0; lin < this->nb_lin; lin++)
{
int col;
for (col = 0; col < this->nb_col; col++)
{
this->tab[lin][col] = PIX_OFF;
}
}
}
}
}
void pix_put (struct screen *this, int lin, int col, int val)
{
if (this != NULL && lin < this->nb_lin && col < this->nb_col)
{
this->tab[lin][col] = val ? PIX_ON : PIX_OFF;
}
}
void pix_refresh (struct screen const *this)
{
if (this != NULL)
{
int lin;
for (lin = 0; lin < this->nb_lin; lin++)
{
int col;
for (col = 0; col < this->nb_col; col++)
{
putchar (this->tab[lin][col]);
}
putchar ('\n');
}
}
}
int main (void)
{
struct screen screen;
pix_init (&screen, NB_LIN, NB_COL);
pix_put (&screen, 4, 8, 1);
pix_refresh (&screen);
return 0;
} |
Partager