bonjour , voici mon programme . je n arrive pas a structurer mon fichier a cause de la fonction inserer_recette_fin_liste qui doit normalement inserer un maillon recette a la fin de la liste mais voila ca plante, j ai mis une pause entre chaque étape, pour voir d ou venait le probleme , et a priori ca plante après le malloc compris dans la fonction.je commence a etre bien perdu, pouvez m aider .si vous voyez des choses incohérentes par hasard , pouvez vous me les signaler.merci d avance.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct recette { char * nom;
struct ingredient * liste_ing;
char * tps;
char * facon;
struct recette * rec_suiv;
}recette;
typedef struct ingredient {char * nom_ing;
char * quantite;
struct ingredient * ing_suiv;
}ingredient;
typedef struct recette * liste_recettes;
typedef struct ingredient * liste_ing;
/*void creer_ingredient(char p
else{i.nom_ing=NULL;
i.quantite=NULL;
i.ing_suiv=NULL;}
}*/
void creer_ingredient(char t0[1000], liste_ing ing){
if (t0[1000]!=':'){
ing=(liste_ing)malloc(sizeof(ingredient));
ing->nom_ing=strtok(NULL,",");
printf("%s\n",ing->nom_ing);
ing->quantite=strtok(NULL,";");
printf("%s\n",ing->quantite);
system ("PAUSE");
creer_ingredient(t0,ing->ing_suiv);
}
else {printf("nothing");
}
}
void inserer_recette_fin_liste(char a[1000],liste_recettes *l) {
char t0[1000];
strcpy(t0,a);
if (l==NULL) {
printf("%s \n",t0);
system("PAUSE");
(*l)=(liste_recettes )malloc(sizeof(recette));
(*l)->nom=strtok(t0,":");//renvoie le string situé avant le premier :
printf("%s\n",(*l)->nom);
system("PAUSE");
creer_ingredient(t0,(*l)->liste_ing);
system("PAUSE");
(*l)->tps=strtok(NULL,":");
printf("%s \n",(*l)->tps);
system("PAUSE");
(*l)->facon=strtok(strrchr(t0,':'),"\n");
printf("%s \n",(*l)->facon);
system("PAUSE");
(*l)->rec_suiv=NULL;
system("PAUSE");
}
else inserer_recette_fin_liste(t0,&((*l)->rec_suiv));
}
void effacer_tab(char t[1000]){
int i;
for (i=0;i<strlen(t);i++) {
t[i]=' ';}
t[0]='\0';}
void structure (liste_recettes *l) {
FILE *r;
char a[1000],c;
int i=0;
r= fopen ("recettes.dat", "r");
if (!r) {printf ("*** Impossible d'ouvrir le fichier ***\n");
system("PAUSE");
//menu();
}
else {while(!feof(r)) {
do { c=fgetc(r);
a[i]=c;
i++;} while (c!='\n');
printf("%s \n\n",a);
system("PAUSE");
inserer_recette_fin_liste(a,l);
i=0;
effacer_tab(a);
}}
}
int main()
{
liste_recettes *l;
l=NULL;
structure(l);
}