debut TP18

This commit is contained in:
2023-11-14 17:28:39 +01:00
parent fd72164c4e
commit 7d4d21b993
8 changed files with 72 additions and 35 deletions

View File

@@ -9,7 +9,8 @@ but : exo1
OFILES = lire.o \
personne.o \
repertoire.o \
main.o
main.o\
option.o
CC = gcc
@@ -21,7 +22,9 @@ personne.o : personne.h lire.h
repertoire.o : repertoire.h personne.h
main.o : personne.h repertoire.h
main.o : personne.h repertoire.h option.h
option.o : option.h
#CHAPITRE 4 : DEPENDANCES AVEC COMMANDES

Binary file not shown.

View File

@@ -4,24 +4,7 @@
#include <stdio.h>
#include "personne.h"
#include "repertoire.h"
typedef enum {AJOUTER, AFFICHER, SORTIR} options;
options saisir_option() {
short o;
printf("\nChoisissez une option :\n");
printf("1] Ajouter une personne.\n");
printf("2] Afficher le repertoire.\n");
printf("3] Sortir\n");
printf("? ");
scanf("%hd", &o);
switch(o) {
case 1 : return AJOUTER;
case 2 : return AFFICHER;
case 3 : return SORTIR;
default : return AFFICHER;
}
}
#include "option.h"
int main(void) {
options opt;

20
DEV1.1/TP17/exo1/option.c Normal file
View File

@@ -0,0 +1,20 @@
#include <stdlib.h>
#include <stdio.h>
#include "option.h"
options saisir_option() {
short o;
printf("\nChoisissez une option :\n");
printf("1] Ajouter une personne.\n");
printf("2] Afficher le repertoire.\n");
printf("3] Sortir\n");
printf("? ");
scanf("%hd", &o);
switch(o) {
case 1 : return AJOUTER;
case 2 : return AFFICHER;
case 3 : return SORTIR;
default : return AFFICHER;
}
}

10
DEV1.1/TP17/exo1/option.h Normal file
View File

@@ -0,0 +1,10 @@
/* TP 19 Exercice 1 : fichier option.h */
#ifndef OPTION_H
#define OPTION_H
typedef enum {AJOUTER, AFFICHER, SORTIR} options;
options saisir_option();
#endif /* OPTION_H/

View File

@@ -1,15 +0,0 @@
#ifndef _GRAPH_H
#define _GRAPH_H
: protection contre les inclusions multiples
#include<X11/Xlib.h> : une directive d'inclusion
#define NB_PIXMAP 10 : création d'une constante
void CacherFenetre(void); :prototype d'une fonction
/* cache la fenetre */ : une directive de définition
extern int _Y; : une déclaration externe de variable globale
typedef unsigned long couleur; :une déclaration de type

BIN
DEV1.1/TP18/singleton Executable file

Binary file not shown.

36
DEV1.1/TP18/singleton.c Normal file
View File

@@ -0,0 +1,36 @@
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int taille,val=1,val1,occ;
int* tab=NULL;
int* tab_val=NULL;
printf("Nombre de réel à entrer: ");
scanf("%d",&taille);
tab = (int*) malloc(taille*sizeof(int));
tab_val = (int*) malloc(taille*sizeof(int));
printf("Réel à entrer: ");
scanf("%d",tab);
while(val<taille){
printf("Réel à entrer: ");
scanf("%d",&tab[val]);
val++;
}
printf("%d ",tab[0]);
tab_val[0]=tab[0];
for(val=1;val<taille;val++){
occ=0;
for(val1=0;val1<taille;val1++){
if (tab[val]==tab_val[val1])
occ++;
}
if (occ==0)
printf("%d ",tab[val]);
tab_val[val]=tab[val];
}
free(tab);
free(tab_val);
printf("\n");
return EXIT_SUCCESS;
}