tp ou jai lu le debut de killing stalking
This commit is contained in:
parent
bf1a1e41b9
commit
93ffb9240a
98
DEV1.1/TD/TD10.c
Normal file
98
DEV1.1/TD/TD10.c
Normal file
@ -0,0 +1,98 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
struct blob{
|
||||
char faction;
|
||||
int taille;
|
||||
};
|
||||
|
||||
typedef struct blob blob;
|
||||
|
||||
struct arene{
|
||||
blob combattant[50];
|
||||
};
|
||||
|
||||
typedef struct arene arene;
|
||||
|
||||
void printBlob(blob b) {
|
||||
printf("Faction : %c\nTaille : %d\n",b.faction, b.taille);
|
||||
}
|
||||
|
||||
blob rencontre(blob blob1,blob blob2) {
|
||||
int tailleOut;
|
||||
char factionOut;
|
||||
if (blob1.faction==blob2.faction)
|
||||
{
|
||||
tailleOut = blob1.taille + blob2.taille;
|
||||
factionOut = blob1.faction;
|
||||
}
|
||||
if (blob1.faction!=blob2.faction)
|
||||
{
|
||||
if (blob1.taille>blob2.taille)
|
||||
{
|
||||
tailleOut = blob1.taille-blob2.taille;
|
||||
factionOut = blob1.faction;
|
||||
}
|
||||
if (blob1.taille<blob2.taille)
|
||||
{
|
||||
tailleOut = blob2.taille-blob1.taille;
|
||||
factionOut = blob2.faction;
|
||||
}
|
||||
if (blob1.taille==blob2.taille)
|
||||
{
|
||||
tailleOut = 1;
|
||||
factionOut = blob1.faction;
|
||||
}
|
||||
}
|
||||
blob b={factionOut,tailleOut};
|
||||
return b;
|
||||
}
|
||||
|
||||
void remplirArene(arene* a) {
|
||||
srand(time(0));
|
||||
int taille;
|
||||
char faction;
|
||||
for (int i = 0; i < 50; ++i)
|
||||
{
|
||||
taille = (rand() % 40)+1;
|
||||
faction = ((rand() % 5)+'a');
|
||||
blob b={faction, taille};
|
||||
((*a).combattant[i])=b;
|
||||
}
|
||||
}
|
||||
|
||||
void afficherArene(arene a) {
|
||||
for (int i = 0; i < 50; ++i)
|
||||
{
|
||||
printf("Participant n°%d \n",i+1);
|
||||
printBlob(a.combattant[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
/*
|
||||
blob a={'a',5};
|
||||
blob b={'a',10};
|
||||
blob c=rencontre(a,b);
|
||||
printBlob(a);
|
||||
printBlob(b);
|
||||
printBlob(c);
|
||||
*/
|
||||
|
||||
arene liguePkmn;
|
||||
remplirArene(&liguePkmn);
|
||||
afficherArene(liguePkmn);
|
||||
|
||||
blob res=liguePkmn.combattant[0];
|
||||
int i;
|
||||
for (int i = 1; i < 50; ++i)
|
||||
{
|
||||
res=rencontre(res,liguePkmn.combattant[i]);
|
||||
printBlob(res);
|
||||
}
|
||||
|
||||
printBlob(res);
|
||||
return 0;
|
||||
}
|
0
DEV1.1/TD/TD10.txt
Normal file
0
DEV1.1/TD/TD10.txt
Normal file
32
DEV1.1/TP11/complexes.c
Normal file
32
DEV1.1/TP11/complexes.c
Normal file
@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
struct complexe{
|
||||
double x;
|
||||
double y;
|
||||
};
|
||||
|
||||
int module(struct complexe cp){
|
||||
return sqrt(pow(cp.x,2)+pow(cp.y,2));
|
||||
}
|
||||
|
||||
void inverse(struct complexe cp){
|
||||
printf("%d + I * %d\n",cp.x/pow(module(cp),2),cp.y/pow(module(cp),2));
|
||||
}
|
||||
|
||||
void conjugue(struct complexe cp){
|
||||
printf("%d - %d * I\n", cp.x, cp.y);
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
struct complexe lol={2.785,5.233};
|
||||
double lolol=module(lol);
|
||||
printf("%d \n",lolol);
|
||||
conjugue(lol);
|
||||
inverse(lol);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
13
DEV1.1/TP11/date.c
Normal file
13
DEV1.1/TP11/date.c
Normal file
@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
time_t timestamp = time(NULL);
|
||||
struct tm * timeInfos = localtime(& timestamp);
|
||||
printf("%04d/%02d/%02d\n", timeInfos->tm_year+1900, timeInfos->tm_mon+1,timeInfos->tm_mday);
|
||||
return 0;
|
||||
}
|
38
DEV1.1/TP11/groupe.c
Normal file
38
DEV1.1/TP11/groupe.c
Normal file
@ -0,0 +1,38 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <grp.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
struct group *grp;
|
||||
|
||||
char grpname[]="senart22", **curr;
|
||||
/*
|
||||
if ((grp= getgrnam(grpname))== NULL)
|
||||
printf("pas de groupe a ce nom");
|
||||
else
|
||||
{
|
||||
printf("Membre du groupe %s : \n", grpname);
|
||||
for (curr=grp->gr_mem; (*curr) != NULL; curr++)
|
||||
printf(" %s\n", *curr);
|
||||
}*/
|
||||
|
||||
struct group etu;
|
||||
etu=*getgrname("senart22");
|
||||
|
||||
int i=0;
|
||||
while(*etu.gr_name[i]!=NULL)
|
||||
{
|
||||
for (int j = 0; j < sizeof(etu.gr_name[i]); ++j)
|
||||
{
|
||||
printf("%s",etu.gr_name[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
17
DEV1.1/TP11/tailles.c
Normal file
17
DEV1.1/TP11/tailles.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct blablabla{
|
||||
int a;
|
||||
char b;
|
||||
char c;
|
||||
};
|
||||
|
||||
typedef struct blablabla abc;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
abc blabla={50,'a','c'};
|
||||
printf("%d \n", sizeof(blabla) );
|
||||
return 0;
|
||||
}
|
BIN
DEV1.1/TP12/exo1.tar.gz
Normal file
BIN
DEV1.1/TP12/exo1.tar.gz
Normal file
Binary file not shown.
41
DEV1.1/TP12/exo1/Makefile
Normal file
41
DEV1.1/TP12/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/TP12/exo1/exo1
Executable file
BIN
DEV1.1/TP12/exo1/exo1
Executable file
Binary file not shown.
8
DEV1.1/TP12/exo1/lire.h
Normal file
8
DEV1.1/TP12/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/TP12/exo1/lire.s
Normal file
30
DEV1.1/TP12/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/TP12/exo1/main.c
Normal file
42
DEV1.1/TP12/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/TP12/exo1/personne.c
Normal file
33
DEV1.1/TP12/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/TP12/exo1/personne.h
Normal file
16
DEV1.1/TP12/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 */
|
38
DEV1.1/TP12/exo1/repertoire.c
Normal file
38
DEV1.1/TP12/exo1/repertoire.c
Normal file
@ -0,0 +1,38 @@
|
||||
/* 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/TP12/exo1/repertoire.h
Normal file
20
DEV1.1/TP12/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 */
|
20
DEV1.1/TP12/texte.txt
Normal file
20
DEV1.1/TP12/texte.txt
Normal file
@ -0,0 +1,20 @@
|
||||
1. des fonctions
|
||||
|
||||
|
||||
|
||||
as -o lire.o lire.s
|
||||
gcc -Wall -ansi -pedantic -g -c -o personne.o personne.c
|
||||
gcc -Wall -ansi -pedantic -g -c -o repertoire.o repertoire.c
|
||||
gcc -Wall -ansi -pedantic -g -c -o main.o main.c
|
||||
gcc -Wall -ansi -pedantic -g -o exo1 lire.o personne.o repertoire.o main.o
|
||||
|
||||
|
||||
non
|
||||
|
||||
il a rien fait
|
||||
|
||||
il execute que les commande ou repertoire est mentionnée
|
||||
|
||||
main.o: main.c personne.h repertoire.h
|
||||
|
||||
les dependance ???
|
Loading…
Reference in New Issue
Block a user