This is the code am trying to build and run (it's about automat non d to adf) but it shows me what I mentioned above and when am about to enter the states in the 2nd function it's an infinity loop //it may have some unused variables but you can ignore those as the problem doesn't lie in them I think it's in the tabs and the pointer and equals to but I can't really find out how to fix it
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#include<string.h>
char* tab[10][10];
char* T[20][20];
char F[2];
int n,m;
int i,j;
int H=0,V=0;
char* Q="-1";
char X;
int Y;
typedef struct stack_char
{
char val_char;
struct stack_char* next;
}stack_char;
stack_char* headd=NULL,*r,*e;
typedef struct pile
{
int Value;
struct pile* next;
}pile;
pile* head=NULL,*q,*p;
void aff_pile()
{
pile*p;
if(head==NULL)printf("pile empty");
else
{
p=head;
while(p!=NULL)
{
printf("\n result : %d \n",p->Value);
p=p->next;
}
}
}
void aff_stack_char()
{
stack_char*p;
if(headd==NULL){printf("stack empty");}
else
{
p=headd;
while(p!=NULL)
{
printf("\n the list of symbols is : %d \n",p->val_char);
p=p->next;
}
}
}
void sstack_char(char X)
{
r=(stack_char*)malloc(sizeof(pile));
r->val_char=X;
r->next=NULL;
if(headd==NULL){headd=r;}
else
{
r->next=headd;
headd=r;
}
printf("the Stack symbol is : %c",p->Value);
}
char unstack_char()
{
char X;
if(headd!=NULL)
{
e=headd;
X=e->val_char;
headd=e->next;
free(e);
e=headd;
printf("the Unstack value is : %c \n\n",X);
}
else
{
printf("the Stack is empty \n");
}
return X;
}
void empiler(int Y)
{
q=(pile*)malloc(sizeof(pile));
q->Value=Y;
q->next=NULL;
if(head==NULL) {head=q;}
else
{
q->next=head;
head=q;
}
printf("the Stack states are : %d \n\n",q->Value);
}
int depiler()
{
int Y;
if(head!=NULL){p=head; Y=p->Value; head=p->next; free(p); p=head;
printf("The Unstack value is : %d \n\n",Y);}
else{ printf("the stack is empty \n");}
return Y;
}
void add_stack_states()
{
int H,E;
printf("enter the number of states :");
scanf("%d",&m);
H=1;
while(H!=m+1){
printf("enter the states :");
scanf("%d",&E);
empiler(E);
H++;
}
aff_pile();
}
void add_stack_symbols()
{
int h,n;
char S;
printf("enter the number of symbols :");
scanf("%d",&n);
h=1;
while(h!=n){
printf("enter the symbol:");
scanf("%c",&S);
h++;
sstack_char(S);
}
aff_stack_char();
}
void menu(){
printf("\n");
printf("+--------------------------------------+\n");
printf("| 1:->add_stack_symbols |\n");
printf("| 2:->add_stack_states |\n" );
printf("| 3:->ADFND_presentation |\n");
printf("| 4:->extend_closure |\n");
printf("+--------------------------------------+\n");
}
void ADFND_presentation()
{
int c;
i=0;
j=0;
int con;
char jj;
for (i=1;i<=n;i++)
{
jj=unstack_char();
tab[i][0]=jj;
}
for(j=1;j<=m;j++){
depiler(Y);
tab[0][j]=Y;
}
for(j=1;j<=m;j++){
for (i=1;i<=n;i++){
while(con ==1){
printf("enter the transition of tab[0][%d] with tab[%d][0] si est il exist si non entrer -2",j,i);
scanf("%c",&c);
if(c==-2){
tab[i][j]='\0';
}
else{
tab[i][j]=c;
}
printf("if you want to enter another transition enter '1' else enter '0'");
scanf("%d",&con);
}
}
}
}
void extend_closure(){
int co;
i=0;
while(tab[i][0]!=Q){
i++;
co=i;
}
if(tab[co][1]!='\0'){
F[0]=tab[co][1];
F[1]='0';
printf("the closure is %s",F[2]) ;
}else{
F[0]='0';
printf(" the closure is %s",F[2]) ;
}
}
int main(){
int g=0;
do
{
menu();
scanf ("%d",&g);
switch (g){
case 1 : {add_stack_states();break;}
case 2 : {add_stack_symbols();break;}
case 3 : {ADFND_presentation();break;}
case 4 : {extend_closure();break;}
}
}while (g!=5);
return 0;
}
User contributions licensed under CC BY-SA 3.0