Affichage de caractere dans une grille

Résolu
anzelus Messages postés 9 Date d'inscription vendredi 5 novembre 2004 Statut Membre Dernière intervention 14 mai 2006 - 13 déc. 2004 à 21:58
anzelus Messages postés 9 Date d'inscription vendredi 5 novembre 2004 Statut Membre Dernière intervention 14 mai 2006 - 14 déc. 2004 à 10:34
bonjour,
voila, je suis un debutant en c, je dois faire un programme qui affiche une grille de points sur console, apres afficher un caractere speciale à la place d'un des points apres avoir entrer ses cordonnes. et c'est la que ça bloque, je ne sais pas comment, voila le code source que j'ai ecrit...aidez moi svp
merci

#include<stdio.h>
#include<stdlib.h>
#include<math.h>

/*programme d'affichage de la grille*/

affichagegrille(int x,int y){

int l,k,i,j;
printf(" ");

for(l=1;l<y+1;l++){
if(l<10)
printf("%d ",l);
else
printf("%d ",l);
}
printf("\n");
printf("\n");
for(k=1;k<x+1;k++){
if(k<10)
printf(" %d",k);
else
printf("%d",k);

for(j=0;j<y;j++){
printf(" .");
}

printf("\n\n");

}

}

/*affichage d'un caractere special*/
//je bloque sur cette fonction

/* affichage_caracteres(int maxx,int maxy){
int t,s;

printf(" ");

for(t=1;t<maxy+1;t++){
if(t<10)
printf("%d ",t);
else
printf("%d ",t);
}
printf("\n");
printf("\n");

for(s=1;s<maxx;s++){
printf("entrer les positions des caracteres dans la ligne %d \n",s);
scanf(

} */

/* Début du programme principal */

main(){
int xmax,ymax,g,h,maxx,maxy,s;
printf("entrer nb de lignes, nb de colonnes\n");
scanf("%d\n",&xmax);
scanf("%d",&ymax);
maxy=ymax;
maxx=xmax;

affichagegrille(xmax,ymax);

printf("entrer les cordonnee\n");
scanf("%d\n",&h);
scanf("%d",&g);

//affichage_caracteres(maxx,maxy);

system("PAUSE");
return 0;
}

2 réponses

cs_6co Messages postés 114 Date d'inscription lundi 27 janvier 2003 Statut Membre Dernière intervention 5 avril 2012 1
14 déc. 2004 à 01:35
bonsoir anzelus, peut être bien que tu bloques parce que tu cherches un peu trop compliqué...
voilà ce que je propose :

#include<stdio.h>
#include<stdlib.h>

void affiche_grille(unsigned int xmax, unsigned int ymax, unsigned int coordx, 
                        unsigned int coordy)
{
 unsigned int i,j;   
 printf("  ");      
 for (i=1; i<=xmax; i++) printf("%2i",i);
 
 for (i=1; i<=ymax; i++)
 {
  printf("\n");
  printf("%2i",i);   
  for (j=1; j<=xmax; j++)
  if (coordx==i && coordy==j)
  printf(" *");
  else
  printf(" .");
      
 }   
}

int main(void)
{
 unsigned int haut, larg, x, y;   
 printf("Entrez la hauteur et la largeur du tableau\n");
 scanf("%i",&haut);
 scanf("%i",&larg);   
 affiche_grille(larg,haut,0,0);
 
 printf("Entrer coordonnées x et y du caractère spécial\n");
 scanf("%i",&x);
 scanf("%i",&y);
 
 
 affiche_grille(larg,haut,x,y);       
 
 system("PAUSE");      
}    


j'espère que ça répond à ton problème
bonne prog

6co
3
Rejoignez-nous