Problème d'affectation d'un mot ds un tableau de char

Résolu
deck_bsd Messages postés 1243 Date d'inscription jeudi 31 mars 2005 Statut Membre Dernière intervention 3 août 2016 - 25 sept. 2005 à 13:14
cs_Joky Messages postés 1787 Date d'inscription lundi 22 novembre 2004 Statut Membre Dernière intervention 31 janvier 2009 - 25 sept. 2005 à 13:23
Bonjour

j'ai un petit problème d'affectation d'un mots dans un tableau de char.

voici le code ou j'ai le problème . J'ai réussi à situer la faute mais je n'arrive pas à la corriger.



code :



void selection_aleatoire()

{



short D_shrandom;

int D_inti=0;

char D_chmots[6][20],D_chmot[20];

FILE *D_fichier;



D_fichier= fopen("mots.dat","r");

while(fgets(D_chmot,20,D_fichier)!=0)

{

D_inti++;


strcpy(D_chmots[D_inti],D_chmot); <---erreur ici
"acces violation sous Borland C++ Builder.

printf("%s",D_chmots[D_inti]);

}

fclose(D_fichier);

getch();

randomize;

D_shrandom=random(6);//D_shrandom = ((rand()+time(NULL))%20);

strcpy(D_chmot,D_chmots[D_shrandom]);

printf("%s",D_chmot);

getch();

}

Merci d'avance pour votre aide.

++All

2 réponses

cs_Joky Messages postés 1787 Date d'inscription lundi 22 novembre 2004 Statut Membre Dernière intervention 31 janvier 2009 2
25 sept. 2005 à 13:23
Ah non lol :)

D_Init = 0;



D_Init++; //D_Init = 1



D_ChMots[D_Init] -> D_ChMots[1]

Et un tableau ca commence pas à 0 par hasard ?

if(!Meilleur("Joky")) return ERREUR;<
3
cs_Joky Messages postés 1787 Date d'inscription lundi 22 novembre 2004 Statut Membre Dernière intervention 31 janvier 2009 2
25 sept. 2005 à 13:22
Au pif, je dirais le caractère terminal :)


D_chmot[20+1]; essai ça ptete :)
if(!Meilleur("Joky")) return ERREUR;<
0
Rejoignez-nous