This commit is contained in:
Simon SAYE BABU 2023-01-11 14:14:52 +01:00
parent c3fdadd6c0
commit e4498c21e7
6 changed files with 209 additions and 2 deletions

View File

@ -29,7 +29,6 @@ int main(int argc, char const *argv[])
{
printf(">");
scanf("%c%c",&input1,&input2);
fflush(stdin);
}
}
}

56
DEV1.1/TP15/file.c Normal file
View File

@ -0,0 +1,56 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct pile
{
int tete;
char ple[10];
};
typedef struct pile pile;
int empty(pile *p)
{
if(p==NULL)
{
return 1;
}
return p->tete==0;
}
char pop(pile **p)
{
(*p)->tete--;
return (*p)->ple[(*p)->tete];
}
void push(pile **p,char v)
{
if (*p==NULL)
{
pile *new=malloc(sizeof(pile));
new->tete=0;
*p=new;
push(p,v);
}else
{
(*p)->ple[(*p)->tete]=v;
(*p)->tete++;
}
}
char top(pile **p)
{
char temp = pop(p);
push(p,temp);
return temp;
}
void clear(pile **p)
{
while(!empty((*p)))
{
pop(p);
}
}

1
DEV1.1/TP15/patate Normal file
View File

@ -0,0 +1 @@
([{{{{[[((())])]}}}}])

View File

@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct pile
{
@ -53,3 +54,88 @@ void clear(pile **p)
pop(p);
}
}
int main(int argc, char const *argv[])
{
FILE *f;
f=fopen(argv[1],"r");
pile *test = malloc(sizeof(pile));
char c;
char temp;
int verif;
fread(&c,1,1,f);
while(!feof(f)==1)
{
printf("%c\n", c);
if (c=='('||c=='['||c=='{')
{
push(&test,c);
}
else
{
if (c==')'||c==']'||c=='}')
{
verif = 0;
if (!empty(test))
{
temp = pop(&test);
printf("c = %c et test = %c\n",c,temp);
switch(c)
{
case ')':
if (temp == '(')
{
break;
}
else
{
verif++;
}
break;
case ']':
if (temp == '[')
{
break;
}
else
{
verif++;
}
break;
case '}':
if (temp == '{')
{
break;
}
else
{
verif++;
}
break;
default:
break;
}
if (verif!=0)
{
break;
}
}
else
{
printf("Le fichier est mal parenthesé (parenthese en trop) !\n");
return 1;
}
}
}
fread(&c,1,1,f);
}
if (verif!=0)
{
printf("Le fichier est mal parenthesé ! (parenthse au mauvaise endroit)\n");
}
else
{
printf("Le fichier est bien parenthesé !\n");
}
return 0;
}

View File

@ -0,0 +1,2 @@
#include <stdio.h>
#include <stdlib.h>

63
DEV1.1/random/liste.c Normal file
View File

@ -0,0 +1,63 @@
#include <stdio.h>
#include <stdlib.h>
struct file
{
int data;
struct file* succ;
struct file* last;
};
typedef struct file file;
int empty(file *f)
{
return f==NULL;
}
void enqueue(file **f, int v)
{
file *nouveau=malloc(sizeof(file));
nouveau -> data = v;
nouveau -> succ = NULL;
nouveau -> last = nouveau;
if ((*f)!=NULL)
{
(*f) -> last -> succ = nouveau;
(*f) -> last = nouveau;
}
else
{
(*f)=nouveau;
}
}
int dequeue(file **f)
{
int resultat = (*f) -> data;
file *temp = *f;
(*f)=(*f)-> succ;
if ((*f)!=NULL)
{
(*f) -> last = temp -> last;
}
free(temp);
return resultat;
}
int main(int argc, char const *argv[])
{
file *f = NULL;
for (int i = 0; i < 15; ++i)
{
enqueue(&f,i);
}
int i=0;
while(!empty(f))
{
printf("%s\n",dequeue(&f) );
}
return 0;
}