Tableau en C

Bonjour,
Je débute en C et j’ai quelque soucis avec les tableaux.
Je souhaites stocker des données dans deux tableaux.
Tab1= jetons = couleur valeur img
tab2= cartes= noms img

et que mon main appelle la fonction pour créer les tableaux et par la suite fasse un random etc (ca ce sera après) mais là j’ai déjà pas mal d’erreur avec ce code si quelqu’un peut m’aider.
Merci davance


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

#include <constants.h>

char tableau_cartes[51+1];/*[1]*/

void creation_tableu_jetons () //Attention aux pointeurs!
{
	char	tableau_jetons[4][3] = {{"Noirs", "500", "jetons_noirs.png"},{"Rouge", "300", "jetons_rouges.png"},
		{"Vert", "5", "jetons_verts.png"},{"Bleu","120","jetons_bleus.png"}};
/*	
	tableau_jetons[0][0] = "Noirs";
	tableau_jetons[0][1] = "500";
	tableau_jetons[0][2] = "jetons_noirs.png";
	
	tableau_jetons[1][0] = "Rouge";
	tableau_jetons[1][1] = "300";
	tableau_jetons[1][2] = "jetons_rouges.png";

	tableau_jetons[2][0] = "Bleu";
	tableau_jetons[2][1] = "100";
	tableau_jetons[3][2] = "jetons_bleus.png";
	
	tableau_jetons[3][0] = "Vert";
	tableau_jetons[3][1] = "50";
	tableau_jetons[3][2] = "jetons_verts.png";
 */
}


void creation_tableau_cartes()

{

		//char tableau_cartes[51]; //pas 52 car le 0 compte

tableau_cartes[0]=	"c1";
tableau_cartes[1]=	"c2";
tableau_cartes[2]=	"c3";
tableau_cartes[3]=	"c4";
tableau_cartes[4]=	"c5";
tableau_cartes[5]=	"c6";
tableau_cartes[6]=	"c7";
tableau_cartes[7]=	"c8";
tableau_cartes[8]=	"c9";
tableau_cartes[9]=	"c10";
tableau_cartes[10]=	"c11";
tableau_cartes[11]=	"c12";
tableau_cartes[12]=	"c13";
tableau_cartes[13]=	"ca1";
tableau_cartes[14]=	"ca2";
tableau_cartes[15]=	"ca3";
tableau_cartes[16]=	"ca4";
tableau_cartes[17]=	"ca5";
tableau_cartes[18]=	"ca6";
tableau_cartes[19]=	"ca7";
tableau_cartes[20]=	"ca8";
tableau_cartes[21]=	"ca9";
tableau_cartes[22]=	"ca10";
tableau_cartes[23]=	"ca11";
tableau_cartes[24]=	"ca12";
tableau_cartes[25]=	"ca13";
tableau_cartes[26]=	"p1";
tableau_cartes[27]=	"p2";
tableau_cartes[28]=	"p3";
tableau_cartes[29]=	"p4";
tableau_cartes[30]=	"p5";
tableau_cartes[31]=	"p6";
tableau_cartes[32]=	"p7";
tableau_cartes[33]=	"p8";
tableau_cartes[34]=	"p9";
tableau_cartes[35]=	"p10";
tableau_cartes[36]=	"p11";
tableau_cartes[37]=	"p12";
tableau_cartes[38]=	"p13";
tableau_cartes[39]=	"t1";
tableau_cartes[40]=	"t2";
tableau_cartes[41]=	"t3";
tableau_cartes[42]=	"t4";
tableau_cartes[43]=	"t5";
tableau_cartes[44]=	"t6";
tableau_cartes[45]=	"t7";
tableau_cartes[46]=	"t8";
tableau_cartes[47]=	"t9";
tableau_cartes[48]=	"t10";
tableau_cartes[49]=	"t11";
tableau_cartes[50]=	"t12";
tableau_cartes[51]=	"t13";

	afficher;
}

void afficher(char tableau_cartes, int n, int i, char message)

{   
	for(i=0;n<9;i++) 
	{ 
		for(n=0;n<9;n++) 
		{
		printf("\test: %c", tableau_cartes[n][i]); 
		
		printf("\n"); 
		
	}
}
	

C’est quoi tes erreurs ? Et tu sais que si tu as un tableau défini tel que :

char tableau_cartes[51+1];/[1]/

Cela veut dire que tu as un tableau de char.

Visiblement, tu essayes d’y coller des const char* ce qui n’est pas du tout la même chose (à priori sizeof(char) != sizeof(const char*)).

Le bon type de tableau_cartes devrait être const char* tableau_cartes[51+1];

Ensuite, ta fonction afficher ne peut pas fonctionner : tu lui passe un char, et non un pointeur ou un tableau, tu ne peux donc pas accéder au n-ième élément.

Merci de ta réponse!
Donc je viens de revoir mon code.
Erreur en bas

Merci d’avance

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

#include <constants.h>

const char* tableau_cartes[51];


void creation_tableu_jetons () //Attention aux pointeurs!
{
const	char	*tableau_jetons[4][3] = {{"Noirs", "500", "jetons_noirs.png"},{"Rouge", "300", "jetons_rouges.png"},
		{"Vert", "5", "jetons_verts.png"},{"Bleu","120","jetons_bleus.png"}};
	
}


void creation_tableau_cartes(int i, int n)

{
	
	tableau_cartes[0]=	"c1";
	tableau_cartes[1]=	"c2";
	tableau_cartes[2]=	"c3";
	tableau_cartes[3]=	"c4";
	tableau_cartes[4]=	"c5";
	tableau_cartes[5]=	"c6";
	tableau_cartes[6]=	"c7";
	tableau_cartes[7]=	"c8";
	tableau_cartes[8]=	"c9";
	tableau_cartes[9]=	"c10";
	tableau_cartes[10]=	"c11";
	tableau_cartes[11]=	"c12";
	tableau_cartes[12]=	"c13";
	tableau_cartes[13]=	"ca1";
	tableau_cartes[14]=	"ca2";
	tableau_cartes[15]=	"ca3";
	tableau_cartes[16]=	"ca4";
	tableau_cartes[17]=	"ca5";
	tableau_cartes[18]=	"ca6";
	tableau_cartes[19]=	"ca7";
	tableau_cartes[20]=	"ca8";
	tableau_cartes[21]=	"ca9";
	tableau_cartes[22]=	"ca10";
	tableau_cartes[23]=	"ca11";
	tableau_cartes[24]=	"ca12";
	tableau_cartes[25]=	"ca13";
	tableau_cartes[26]=	"p1";
	tableau_cartes[27]=	"p2";
	tableau_cartes[28]=	"p3";
	tableau_cartes[29]=	"p4";
	tableau_cartes[30]=	"p5";
	tableau_cartes[31]=	"p6";
	tableau_cartes[32]=	"p7";
	tableau_cartes[33]=	"p8";
	tableau_cartes[34]=	"p9";
	tableau_cartes[35]=	"p10";
	tableau_cartes[36]=	"p11";
	tableau_cartes[37]=	"p12";
	tableau_cartes[38]=	"p13";
	tableau_cartes[39]=	"t1";
	tableau_cartes[40]=	"t2";
	tableau_cartes[41]=	"t3";
	tableau_cartes[42]=	"t4";
	tableau_cartes[43]=	"t5";
	tableau_cartes[44]=	"t6";
	tableau_cartes[45]=	"t7";
	tableau_cartes[46]=	"t8";
	tableau_cartes[47]=	"t9";
	tableau_cartes[48]=	"t10";
	tableau_cartes[49]=	"t11";
	tableau_cartes[50]=	"t12";
	tableau_cartes[51]=	"t13";
	
	afficher(tableau_cartes[n][i]);
}

void afficher(char *tableau_cartes, int n, int i)

{   
	for(i=0;n<9;i++) 
	{ 
		for(n=0;n<9;n++) 
		{
			printf("\test: %c", *tableau_cartes[n][i]); 
			
			printf("\n"); 
			
		}
	}

Comme erreur j’ai:
printf("\test: %c", *tableau_cartes[n][i]); ; character too long for this type

void afficher(char *tableau_cartes, int n, int i)
{ :confliting types for ‘afficher’

printf("\test: %c", *tableau_cartes[n][i]); : subscripted value is neither array nor pointer

C’est sûr. Tu confond tout. Ton appel de fonction est :

afficher(tableau_cartes[n][i]);

ce qu’il déduit en :

afficher((const char*[]) [n][i]);
afficher((const char*)[i]);
afficher((const char));

Ce qui n’a rien à voir avec un pointeur…

Je suppose que tu devrais faire afficher(tableau_cartes), et changer le prototype de la fonction, genre :

void afficher(const char* tableau_cartes[], int n, int i)

Ceci dit, je ne comprend pas ce que tu veux faire…
Edité le 17/04/2010 à 09:29

En gros c’est un jeu de P.O.K.E.R
Donc je crée un jeu de carte et un autre tableau pour les jetons.

les .png c’est pour afficher après en SDL.

Là je cherche aussi à afficher mon tableau pour tester.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SDL.h"
#include "SDL_image.h"
#include "SDL_ttf.h"
#include <constants.h>

const char* tableau_cartes[51];

void creation_tableu_jetons () //Attention aux pointeurs!
{
	const	char	*tableau_jetons[4][3] = {{"Noirs", "500", "jetons_noirs.png"},{"Rouge", "300", "jetons_rouges.png"},
		{"Vert", "5", "jetons_verts.png"},{"Bleu","120","jetons_bleus.png"}};
	
}


void creation_tableau_cartes(int i, int n)

{
	
	tableau_cartes[0]=	"c1";
	tableau_cartes[1]=	"c2";
	tableau_cartes[2]=	"c3";
	tableau_cartes[3]=	"c4";
	tableau_cartes[4]=	"c5";
	tableau_cartes[5]=	"c6";
	tableau_cartes[6]=	"c7";
	tableau_cartes[7]=	"c8";
	tableau_cartes[8]=	"c9";
	tableau_cartes[9]=	"c10";
	tableau_cartes[10]=	"c11";
	tableau_cartes[11]=	"c12";
	tableau_cartes[12]=	"c13";
	tableau_cartes[13]=	"ca1";
	tableau_cartes[14]=	"ca2";
	tableau_cartes[15]=	"ca3";
	tableau_cartes[16]=	"ca4";
	tableau_cartes[17]=	"ca5";
	tableau_cartes[18]=	"ca6";
	tableau_cartes[19]=	"ca7";
	tableau_cartes[20]=	"ca8";
	tableau_cartes[21]=	"ca9";
	tableau_cartes[22]=	"ca10";
	tableau_cartes[23]=	"ca11";
	tableau_cartes[24]=	"ca12";
	tableau_cartes[25]=	"ca13";
	tableau_cartes[26]=	"p1";
	tableau_cartes[27]=	"p2";
	tableau_cartes[28]=	"p3";
	tableau_cartes[29]=	"p4";
	tableau_cartes[30]=	"p5";
	tableau_cartes[31]=	"p6";
	tableau_cartes[32]=	"p7";
	tableau_cartes[33]=	"p8";
	tableau_cartes[34]=	"p9";
	tableau_cartes[35]=	"p10";
	tableau_cartes[36]=	"p11";
	tableau_cartes[37]=	"p12";
	tableau_cartes[38]=	"p13";
	tableau_cartes[39]=	"t1";
	tableau_cartes[40]=	"t2";
	tableau_cartes[41]=	"t3";
	tableau_cartes[42]=	"t4";
	tableau_cartes[43]=	"t5";
	tableau_cartes[44]=	"t6";
	tableau_cartes[45]=	"t7";
	tableau_cartes[46]=	"t8";
	tableau_cartes[47]=	"t9";
	tableau_cartes[48]=	"t10";
	tableau_cartes[49]=	"t11";
	tableau_cartes[50]=	"t12";
	tableau_cartes[51]=	"t13";
	
	afficher(tableau_cartes);

void afficher(const char* tableau_cartes[], int n, int i)



{   
	for(i=0;n<9;i++) 
	{ 
		for(n=0;n<9;n++) 
		{
			printf("\test: %c", *tableau_carstes[n][i]); 
			
			printf("\n"); 
			
		}
	}


J’ai comme erreur:
[Photo supprimée]
Edité le 17/04/2010 à 15:04

Ton affichage ne risque pas de fonctionner, car la fonction afficher prend 3 arguments… donc soit tu vires les arguments n et i, soit tu les ajoutes lors de l’appel.

Tu peux essayé ce code :


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


char tableau_cartes[52][10];
char *tableau_jetons[4][3] = {
		{ "Noirs", "500", "jetons_noirs.png" },
		{ "Rouge", "300", "jetons_rouges.png" },
		{ "Vert", "5", "jetons_verts.png" },
		{ "Bleu", "120", "jetons_bleus.png" }
};

void afficher();
void creation_tableau_cartes();

void creation_tableau_cartes() {
	strcpy(tableau_cartes[0], "c1");
	strcpy(tableau_cartes[1], "c2");
	strcpy(tableau_cartes[2], "c3");
	strcpy(tableau_cartes[3], "c4");
	strcpy(tableau_cartes[4], "c5");
	strcpy(tableau_cartes[5], "c6");
	strcpy(tableau_cartes[6], "c7");
	strcpy(tableau_cartes[7], "c8");
	strcpy(tableau_cartes[8], "c9");
	strcpy(tableau_cartes[9], "c10");
	strcpy(tableau_cartes[10], "c11");
	strcpy(tableau_cartes[11], "c12");
	strcpy(tableau_cartes[12], "c13");
	strcpy(tableau_cartes[13], "ca1");
	strcpy(tableau_cartes[14], "ca2");
	strcpy(tableau_cartes[15], "ca3");
	strcpy(tableau_cartes[16], "ca4");
	strcpy(tableau_cartes[17], "ca5");
	strcpy(tableau_cartes[18], "ca6");
	strcpy(tableau_cartes[19], "ca7");
	strcpy(tableau_cartes[20], "ca8");
	strcpy(tableau_cartes[21], "ca9");
	strcpy(tableau_cartes[22], "ca10");
	strcpy(tableau_cartes[23], "ca11");
	strcpy(tableau_cartes[24], "ca12");
	strcpy(tableau_cartes[25], "ca13");
	strcpy(tableau_cartes[26], "p1");
	strcpy(tableau_cartes[27], "p2");
	strcpy(tableau_cartes[28], "p3");
	strcpy(tableau_cartes[29], "p4");
	strcpy(tableau_cartes[30], "p5");
	strcpy(tableau_cartes[31], "p6");
	strcpy(tableau_cartes[32], "p7");
	strcpy(tableau_cartes[33], "p8");
	strcpy(tableau_cartes[34], "p9");
	strcpy(tableau_cartes[35], "p10");
	strcpy(tableau_cartes[36], "p11");
	strcpy(tableau_cartes[37], "p12");
	strcpy(tableau_cartes[38], "p13");
	strcpy(tableau_cartes[39], "t1");
	strcpy(tableau_cartes[40], "t2");
	strcpy(tableau_cartes[41], "t3");
	strcpy(tableau_cartes[42], "t4");
	strcpy(tableau_cartes[43], "t5");
	strcpy(tableau_cartes[44], "t6");
	strcpy(tableau_cartes[45], "t7");
	strcpy(tableau_cartes[46], "t8");
	strcpy(tableau_cartes[47], "t9");
	strcpy(tableau_cartes[48], "t10");
	strcpy(tableau_cartes[49], "t11");
	strcpy(tableau_cartes[50], "t12");
	strcpy(tableau_cartes[51], "t13");
	afficher();
}
void afficher() {
	int i;
	for (i = 0; i < 52; i++) {
			printf("\test: %s\n", tableau_cartes[i]);
	}
}

int main() {
	creation_tableau_cartes();
	return EXIT_SUCCESS;
}

Edité le 26/04/2010 à 16:16

parfait merci