Petit problème avec une pile
salut les ami
j'ai un pti problem qui va me rendre fou
dans ce code simple :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 100
typedef struct pile
{
char p[N];
int sommet ;
} pile;
pile k = {0} ;
char dov[3]= { '{','[' ,'(' } ,df[3]= { '}',']' ,')' };
//int rech_indice(char c);
void Empiler(char c);
//char Depiler();
int main (void)
{
char ch[N] , s ;
int i , valide ;
printf("Saisir une expression : \n");
fgets(ch, sizeof ch, stdin);
//gets(ch);
//ch[strlen(ch)] = '\0' ;
for( i=0 ; i<strlen(ch) ; i++ )
{
if ( ch[i]== '{' || ch[i]== '[' || ch[i]== '(' )
{
Empiler( ch[i] );
printf("%c",ch[i]); /* j'ai fais le printf pour verifier */
}
}
getch();
return 0;
}
void Empiler(char c)
{
if(k.sommet < N)
{
k.sommet++;
k.p[k.sommet]=c;
}
else
printf("Plie Pleine .");
} |
mais à l'execution il y a plantation du programme :
Code:
1 2 3 4
|
Saisir une expression :
(a+b[
([[[((({([({({([{([({(({(((((((( |
y a t-il une faute avec cette ligne :
Code:
if ( ch[i]== '{' || ch[i]== '[' || ch[i]== '(' )
car quand j'ai fais debug le compilateur a indiqué cette ligne .