debut TP17
This commit is contained in:
Binary file not shown.
@@ -38,7 +38,7 @@ int main(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* affichage du resultat */
|
/* affichage du resultat */
|
||||||
printf("C(%d, %d) = %d\n", n, k,j-i);
|
printf("C(%d, %d) = %d\n", n, k,(i*i)-j);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
||||||
|
|||||||
BIN
DEV1.1/TP16/binomial1
Executable file
BIN
DEV1.1/TP16/binomial1
Executable file
Binary file not shown.
BIN
DEV1.1/TP17/exo1.tar.gz
Normal file
BIN
DEV1.1/TP17/exo1.tar.gz
Normal file
Binary file not shown.
41
DEV1.1/TP17/exo1/Makefile
Normal file
41
DEV1.1/TP17/exo1/Makefile
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
# TP 19 Exercice 1 : fichier Makefile
|
||||||
|
|
||||||
|
# CHAPITRE 1 : BUT FINAL
|
||||||
|
|
||||||
|
but : exo1
|
||||||
|
|
||||||
|
# CHAPITRE 2 : VARIABLES
|
||||||
|
|
||||||
|
OFILES = lire.o \
|
||||||
|
personne.o \
|
||||||
|
repertoire.o \
|
||||||
|
main.o
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
|
||||||
|
CFLAGS = -Wall -ansi -pedantic -g
|
||||||
|
|
||||||
|
# CHAPITRE 3 : DEPENDANCES (REGLES IMPLICITES)
|
||||||
|
|
||||||
|
personne.o : personne.h lire.h
|
||||||
|
|
||||||
|
repertoire.o : repertoire.h personne.h
|
||||||
|
|
||||||
|
main.o : personne.h repertoire.h
|
||||||
|
|
||||||
|
#CHAPITRE 4 : DEPENDANCES AVEC COMMANDES
|
||||||
|
|
||||||
|
lire.o : lire.s lire.h
|
||||||
|
as -o lire.o lire.s
|
||||||
|
|
||||||
|
exo1 : $(OFILES)
|
||||||
|
$(CC) $(CFLAGS) -o exo1 $(OFILES)
|
||||||
|
|
||||||
|
#CHAPITRE 5 : NETTOYAGE DES FICHIERS GENERES
|
||||||
|
|
||||||
|
clean :
|
||||||
|
-rm -f $(OFILES) exo1
|
||||||
|
|
||||||
|
#CHAPITRE 6 : BUTS FACTICES
|
||||||
|
|
||||||
|
.PHONY : but clean
|
||||||
BIN
DEV1.1/TP17/exo1/exo1
Executable file
BIN
DEV1.1/TP17/exo1/exo1
Executable file
Binary file not shown.
8
DEV1.1/TP17/exo1/lire.h
Normal file
8
DEV1.1/TP17/exo1/lire.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
/* TP 19 Exercice 1 : fichier lire.h */
|
||||||
|
|
||||||
|
#ifndef LIRE_H
|
||||||
|
#define LIRE_H
|
||||||
|
|
||||||
|
void lire(char*, int);
|
||||||
|
|
||||||
|
#endif /* LIRE_H */
|
||||||
30
DEV1.1/TP17/exo1/lire.s
Normal file
30
DEV1.1/TP17/exo1/lire.s
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
.section .text
|
||||||
|
.globl lire
|
||||||
|
.type lire, @function
|
||||||
|
lire:
|
||||||
|
.LFB0:
|
||||||
|
.cfi_startproc
|
||||||
|
pushq %rbp
|
||||||
|
.cfi_def_cfa_offset 16
|
||||||
|
.cfi_offset 6, -16
|
||||||
|
movq %rsp, %rbp
|
||||||
|
.cfi_def_cfa_register 6
|
||||||
|
|
||||||
|
xorq %rdx, %rdx
|
||||||
|
movl %esi, %edx # taille max
|
||||||
|
movq %rdi, %rsi # adresse chaine
|
||||||
|
movq $0, %rax # read
|
||||||
|
movq $0, %rdi # stdin
|
||||||
|
decq %rdx # place du \0
|
||||||
|
syscall # call read
|
||||||
|
cmpb $10, -1(%rsi, %rax, 1) # si \n
|
||||||
|
jne lire_1
|
||||||
|
decq %rax
|
||||||
|
lire_1: movb $0, (%rsi, %rax, 1) # place \0
|
||||||
|
|
||||||
|
popq %rbp
|
||||||
|
.cfi_def_cfa 7, 8
|
||||||
|
ret
|
||||||
|
.cfi_endproc
|
||||||
|
.LFE0:
|
||||||
|
.size lire, .-lire
|
||||||
42
DEV1.1/TP17/exo1/main.c
Normal file
42
DEV1.1/TP17/exo1/main.c
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/* TP19 Exercice 1 : fichier main.c */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
options opt;
|
||||||
|
repertoire r = construire_repertoire();
|
||||||
|
while ((opt=saisir_option())!=SORTIR)
|
||||||
|
switch(opt) {
|
||||||
|
case AJOUTER :
|
||||||
|
ajouter_personne(r, saisir_personne());
|
||||||
|
break;
|
||||||
|
case AFFICHER :
|
||||||
|
afficher_repertoire(r);
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
; /* rien a faire */
|
||||||
|
}
|
||||||
|
detruire_repertoire(r);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
33
DEV1.1/TP17/exo1/personne.c
Normal file
33
DEV1.1/TP17/exo1/personne.c
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/* TP 19 Exercice 1 : fichier personne.c */
|
||||||
|
|
||||||
|
#include<stdlib.h>
|
||||||
|
#include<stdio.h>
|
||||||
|
#include<string.h>
|
||||||
|
#include "personne.h"
|
||||||
|
#include "lire.h"
|
||||||
|
|
||||||
|
personne construire_personne(const char *nom, const char *tel) {
|
||||||
|
personne p = (personne) malloc(sizeof(struct s_personne));
|
||||||
|
strcpy(p->nom, nom);
|
||||||
|
strcpy(p->tel, tel);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
personne saisir_personne() {
|
||||||
|
personne p = (personne) malloc(sizeof(struct s_personne));
|
||||||
|
printf("\nEntrez le nom de la personne : ");
|
||||||
|
fflush(stdout);
|
||||||
|
lire(p->nom, 30);
|
||||||
|
printf("Entrez son numero de telephone : ");
|
||||||
|
fflush(stdout);
|
||||||
|
lire(p->tel, 20);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void afficher_personne(personne p) {
|
||||||
|
printf("%-30s %-20s\n", p->nom, p->tel);
|
||||||
|
}
|
||||||
|
|
||||||
|
void detruire_personne(personne p) {
|
||||||
|
free(p);
|
||||||
|
}
|
||||||
16
DEV1.1/TP17/exo1/personne.h
Normal file
16
DEV1.1/TP17/exo1/personne.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
/* TP 19 Exercice 1 : fichier personne.h */
|
||||||
|
|
||||||
|
#ifndef PERSONNE_H
|
||||||
|
#define PERSONNE_H
|
||||||
|
|
||||||
|
typedef struct s_personne {
|
||||||
|
char nom[30];
|
||||||
|
char tel[20];
|
||||||
|
} * personne;
|
||||||
|
|
||||||
|
personne construire_personne(const char*, const char*);
|
||||||
|
personne saisir_personne();
|
||||||
|
void afficher_personne(personne);
|
||||||
|
void detruire_personne(personne);
|
||||||
|
|
||||||
|
#endif /* PERSONNE_H */
|
||||||
37
DEV1.1/TP17/exo1/repertoire.c
Normal file
37
DEV1.1/TP17/exo1/repertoire.c
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
/* TP 19 Exercice 1 : fichier repertoire.c */
|
||||||
|
|
||||||
|
#include<stdlib.h>
|
||||||
|
#include<stdio.h>
|
||||||
|
#include "repertoire.h"
|
||||||
|
#include "lire.h"
|
||||||
|
|
||||||
|
repertoire construire_repertoire() {
|
||||||
|
repertoire r = (repertoire) malloc(sizeof(struct s_repertoire));
|
||||||
|
r->taille = 0;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
void afficher_repertoire(repertoire r) {
|
||||||
|
int i = 0;
|
||||||
|
printf("\n%-30s %-20s\n", "Nom", "Telephone");
|
||||||
|
for(; i<r->taille; i++)
|
||||||
|
afficher_personne((r->personnes)[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ajouter_personne(repertoire r, personne p) {
|
||||||
|
if (r->taille<CAPACITE) {
|
||||||
|
(r->personnes)[r->taille] = p;
|
||||||
|
(r->taille)++;
|
||||||
|
return 0;
|
||||||
|
} else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void detruire_repertoire(repertoire r) {
|
||||||
|
int i = r->taille;
|
||||||
|
while(i-->0) {
|
||||||
|
free((r->personnes)[i]);
|
||||||
|
}
|
||||||
|
free(r);
|
||||||
|
}
|
||||||
|
|
||||||
20
DEV1.1/TP17/exo1/repertoire.h
Normal file
20
DEV1.1/TP17/exo1/repertoire.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/* TP 19 Exercice 1 : fichier repertoire.h */
|
||||||
|
|
||||||
|
#ifndef REPERTOIRE_H
|
||||||
|
#define REPERTOIRE_H
|
||||||
|
|
||||||
|
#include "personne.h"
|
||||||
|
|
||||||
|
#define CAPACITE 100
|
||||||
|
|
||||||
|
typedef struct s_repertoire {
|
||||||
|
int taille;
|
||||||
|
personne personnes[CAPACITE];
|
||||||
|
} * repertoire;
|
||||||
|
|
||||||
|
repertoire construire_repertoire();
|
||||||
|
void afficher_repertoire(repertoire);
|
||||||
|
int ajouter_personne(repertoire, personne);
|
||||||
|
void detruire_repertoire(repertoire);
|
||||||
|
|
||||||
|
#endif /* REPERTOIRE_H */
|
||||||
15
DEV1.1/TP17/new 2.txt
Normal file
15
DEV1.1/TP17/new 2.txt
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#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
|
||||||
6
DEV1.1/TP17/tatonnement.txt
Normal file
6
DEV1.1/TP17/tatonnement.txt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
L'ordre coorespond bien à l'ordre de Makefile.
|
||||||
|
Il n'y a plus de commandes car les fichier ont déjà été compilé.
|
||||||
|
oui car c'est le seul que nous avons modifié.
|
||||||
|
on obtient :
|
||||||
|
main.o: main.c personne.h repertoire.h
|
||||||
|
cela donne les inclusion de main.o
|
||||||
Reference in New Issue
Block a user