I have this sheet of code:
listCh remplir(){
char rep;
listCh l,aux,p;
printf("1-veuillez entrer un element?(n pour quitter)\n");
scanf("%c",&rep);
if(rep=='n')
l=NULL;
else{
l=malloc(sizeof(listCh));
printf("2-Donnez la valeur d element!\n");
scanf("%d",&l->valeur);
p=l;
}
while(rep!='n'){
printf("voulez-vous ajouter un nouveau element de la list? (n pour quitter)\n");
scanf("%c",&rep);
if(rep!='n'){
aux=malloc(sizeof(listCh));
printf("Donnez la valeur d element!\n");
scanf("%d",aux->valeur);
p->suiv=aux;
p=aux;
}
else{
p->suiv=NULL;
}
}
return l;
}
There is no error while executing ! But, the problem is that my program escapes the first "scanf" function in the "while" loop.
I didn't find an explanation for this.
I need some help please.
Many thanks :)