JE DETESTE SCANF

This commit is contained in:
Simon SAYE BABU 2023-01-04 15:31:14 +01:00
parent 38dce3951f
commit c3fdadd6c0
4 changed files with 187 additions and 0 deletions

38
DEV1.1/TP15/chaine.c Normal file
View File

@ -0,0 +1,38 @@
#include <stdio.h>
#include <stdlib.h>
#include "pile.h"
int main(int argc, char const *argv[])
{
pile *bazar;
char input1;
char input2;
printf(">");
scanf("%c%c",&input1,&input2);
while(input1!='q')
{
printf("input1=%c input2=%c\n", input1,input2);
if (input1=='+')
{
push(&bazar,input2);
printf("Le charactere %c a été ajouté\n", input2);
input1=' ';
}
else
{
if (input1=='-')
{
printf("Le charactere %c a été supprimé\n",pop(&bazar));
input1=' ';
}
else
{
printf(">");
scanf("%c%c",&input1,&input2);
fflush(stdin);
}
}
}
printf("Au revoir\n");
return 0;
}

55
DEV1.1/TP15/pile.c Normal file
View File

@ -0,0 +1,55 @@
#include <stdio.h>
#include <stdlib.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);
}
}

19
DEV1.1/TP15/pile.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef _pile_h
#define _pile_h
struct pile;
typedef struct pile pile;
int empty(pile *p);
char pop(pile **p);
void push(pile **p,char v);
char top(pile **p);
void clear(pile **p);
#endif

75
DEV1.1/random/TD15.c Normal file
View File

@ -0,0 +1,75 @@
#include <stdio.h>
#include <stdlib.h>
struct pile
{
int tete;
int max;
int ple[10];
}
typedef struct pile pîle;
int empty(pile *p)
{
if(*p==NULL)
{
return 1;
}
return p->tete==0
}
void push(pile **p,int v)
{
if (*p==NULL)
{
pile *new=malloc(sizeof(pile));
new->tete=0;
new->max=2;
int *tab=calloc(2,sizeof(int));
new->ple=tab;
*p=new;
push(p,v);
}else
{
if ((*p)->tete==(*p)->max)
{
int *newtab=calloc(2*(*p)->max,sizeof(int));
for (int i = 0; i < (*p)->max; ++i)
{
*(newtab+i)=*((*p)->ple+i);
}
int *temp=(*p)->ple;
(*p)->max=(*p)->max*=2;
(*p)->ple=newtab;
free(temp);
}
(*p)->ple[(*p)->tete]=v;
(*p)->tete++;
}
}
int pop(pile **p)
{
(*p)->tete--;
return (*p)->ple[(*p)->tete];
}
int main(int argc, char const *argv[])
{
pile *bordel;
return 0;
}
/*
exo 3:
1)
(7*3+7)/7
21,42
*/