Ajout projet deuxième année

This commit is contained in:
Tanguy Herbron 2016-10-14 15:21:09 +02:00
commit dfcaef46a1
464 changed files with 14357 additions and 0 deletions

View File

@ -0,0 +1,61 @@
#include <stdio.h>
#include <stdlib.h>
//Les variables testFourchetteX correspondent aux fourchette de séparation d'un processus.
int main()
{
int testFourchette1, testFourchette2, testFourchette3, testFourchette4, testFourchette5, testFourchette6;
testFourchette1 = fork();
if(testFourchette1 == 0) //Je suis P3, l'enfant de P1
{
boite("Boite 3");
testFourchette2 = fork();
if(testFourchette2 == 0) //Je suis P2, l'enfant de P3
{
boite("Boite 2");
}
else //Je suis P3
{
testFourchette3 = fork();
if(testFourchette3 == 0) //Je suis P4, l'enfant de P3
{
boite("Boite 4");
}
else //Je suis P3, l'enfant de P1
{
testFourchette4 = fork();
if(testFourchette4 == 0) //Je suis P5, l'enfant de P3
{
boite("Boite 5");
testFourchette5 = fork();
if(testFourchette5 == 0) //Je suis P6, l'enfant de P5
{
boite("Boite 6");
}
else //Je suis P5, l'enfant de P3
{
testFourchette6 = fork();
if(testFourchette6 == 0) //Je suis P7, l'enfant de P5
{
boite("Boite 7");
}
else //Je suis P5, l'enfant de P3
{
boite("Boite 5");
}
}
}
else //Je suis P3, l'enfant de P1
{
boite("Boite 3");
}
}
}
}
else //Je suis P1
{
boite("Boite 1");
}
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,110 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <string.h>
#include <errno.h>
#include <arpa/inet.h>
#include <unistd.h>
#define BACKLOG 5
#define MAX 512
int main()
{
fd_set rfds;
struct timeval tv;
struct sockaddr_in infoServer;
struct sockaddr_in retourServer;
socklen_t tailleInfoServ;
int retourSocket;
int retourBind;
int retourListen;
int retourAccept;
int retourRead;
int retourWrite;
char msg[MAX];
infoServer.sin_family = AF_INET;
infoServer.sin_addr.s_addr = htonl(INADDR_ANY);
infoServer.sin_port = htons(3434);
retourSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if(retourSocket == -1)
{
printf("Erreur socket\n");
printf("%s", strerror(errno));
exit(errno);
}
retourBind = bind(retourSocket, (struct sockaddr *)&infoServer, sizeof(infoServer));
if(retourBind == -1)
{
printf("Erreur bind\n");
printf("%s", strerror(errno));
exit(errno);
}
retourListen = listen(retourSocket, BACKLOG);
if(retourListen == -1)
{
printf("Erreur listen\n");
printf("%s", strerror(errno));
exit(errno);
}
printf("Attente d'une connexion.\n\n");
tailleInfoServ = sizeof(retourServer);
retourAccept = accept(retourSocket, (struct sockaddr *)&retourServer, &tailleInfoServ);
if(retourAccept == -1)
{
printf("Erreur accept\n");
printf("%s", strerror(errno));
exit(errno);
}
while(1)
{
FD_ZERO(&rfds);
FD_SET(0, &rfds);
tv.tv_sec = 5;
tv.tv_usec = 0;
printf("Attente d'un nouveau message...\n\n");
if(select(retourSocket+1, &rfds, NULL, NULL, &tv))
{
retourRead = read(retourAccept, &msg, sizeof(msg));
if(retourRead == -1)
{
printf("Erreur read\n");
printf("%s", strerror(errno));
exit(errno);
}
printf("Nouveau message \n");
printf("IP : %s:%d: %s\n\n", inet_ntoa(retourServer.sin_addr), ntohs(retourServer.sin_port), msg);
}
printf("Message : ");
gets(msg);
printf("\n\n");
retourWrite = write(retourAccept, &msg, sizeof(msg));
if(retourWrite == -1)
{
printf("Erreur write\n");
printf("%s", strerror(errno));
exit(errno);
}
}
close(retourAccept);
return 0;
}

View File

@ -0,0 +1,39 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <errno.h>
#include "zone.h"
#include <unistd.h>
#include <time.h>
float randomF()
{
return ((float)100.0*(rand()/(RAND_MAX+0.1)));
}
int main()
{
int i;
zone maZoneMemoire;
key_t clef;
int msqid;
clef = ftok("/tmp/bidon", 5678);
msqid = msgget(clef, 0666 | IPC_CREAT);
if(msqid == -1)
{
printf("Erreur creation file message : %s\n", strerror(errno));
}
while(1)
{
maZoneMemoire.type = randomF();
msgsnd(msqid, (struct msgbuf *) &maZoneMemoire, sizeof(maZoneMemoire), 0);
printf("Nouveau message envoye.\n");
usleep(99999);
}
}

View File

@ -0,0 +1,9 @@
#ifndef ZONE_H_INCLUDED
#define ZONE_H_INCLUDED
typedef struct donnees{
long type;
char texte;
}zone;
#endif // ZONE_H_INCLUDED

View File

@ -0,0 +1,39 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <errno.h>
#include "zone.h"
#include <unistd.h>
#include <time.h>
float randomC()
{
return ((char)('A'+((char)(25.0*(rand()/(RAND_MAX+0.1))))));
}
int main()
{
int i;
zone maZoneMemoire;
key_t clef;
int msqid;
clef = ftok("/tmp/bidon", 5678);
msqid = msgget(clef, 0666 | IPC_CREAT);
if(msqid == -1)
{
printf("Erreur creation file message : %s\n", strerror(errno));
}
while(1)
{
maZoneMemoire.texte = (char)randomC();
msgsnd(msqid, (struct msgbuf *) &maZoneMemoire, sizeof(maZoneMemoire), 0);
printf("Nouveau message envoye.\n");
usleep(99999);
}
}

View File

@ -0,0 +1,9 @@
#ifndef ZONE_H_INCLUDED
#define ZONE_H_INCLUDED
typedef struct donnees{
long type;
char texte;
}zone;
#endif // ZONE_H_INCLUDED

View File

@ -0,0 +1,35 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <errno.h>
#include "zone.h"
#include <unistd.h>
#include <string.h>
int main()
{
zone maZoneMemoire;
key_t clef;
int msqid;
clef = ftok("/tmp/bidon", 5678);
msqid = msgget(clef, 0600 | IPC_CREAT);
if(msqid == -1)
{
printf("Erreur creation file message : %s\n", strerror(errno));
}
while(1)
{
msgrcv(msqid, (struct msgbuf *) &maZoneMemoire, sizeof(maZoneMemoire), 0, 0);
printf("%ul %c\n", maZoneMemoire.type, maZoneMemoire.texte);
usleep(99999);
}
return 0;
}

View File

@ -0,0 +1,9 @@
#ifndef ZONE_H_INCLUDED
#define ZONE_H_INCLUDED
typedef struct donnees{
long type;
char texte;
}zone;
#endif // ZONE_H_INCLUDED

View File

@ -0,0 +1,26 @@
#include <stdio.h>
#include <stdlib.h>
int main ( int argc, char *argv[] )
{
int pid1,pid2;
pid1 = fork();
if ( pid1 == 0 )
{
boite("boite1","pid1=0");
pid2 = fork();
if ( pid2 == 0 )
{
boite("boite2","pid2=0");
}
else
{
boite("boite3","pid2<>0");
}
}
else
{
boite("boite4","pid1<>0");
}
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!\n");
return 0;
}

View File

@ -0,0 +1,48 @@
#include <sys/types.h>
#include <sys/shm.h>
#include <sys/ipc.h>
#include <errno.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
typedef struct {
float temp;
int press;
char ordre;
}uneStruct;
float randomF(){
return ((float)100.0*(rand()/(RAND_MAX+0.1)));
}
int randomI(){
return ((int)100.0*(rand()/(RAND_MAX+0.1)));
}
int main()
{
uneStruct *memShare;
int shmid;
key_t clef;
void *shm;
clef = ftok("/tmp/bidon", 1234);
shmid = shmget(clef, sizeof(uneStruct), 0666);
if(shmid < 0)
{
perror("Erreur shmget");
exit(EXIT_FAILURE);
}
memShare = shmat(shmid, NULL, 0);
while(1)
{
memShare->press = randomI();
memShare->temp = randomF();
printf("Memoire mise a jour.\nVal->\n\tpress : %d, temp : %f\n\n", memShare->press, memShare->temp);
usleep(999999);
}
}

View File

@ -0,0 +1,43 @@
#include <sys/types.h>
#include <sys/shm.h>
#include <sys/ipc.h>
#include <errno.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
typedef struct {
float temp;
int press;
char ordre;
}uneStruct;
char randomC(){
return ((char)126.0*(rand()/(RAND_MAX+0.1)));
}
int main()
{
uneStruct *memShare;
int shmid;
key_t clef;
void *shm;
clef = ftok("/tmp/bidon", 1234);
shmid = shmget(clef, sizeof(uneStruct), 0666);
if(shmid < 0)
{
perror("Erreur shmget");
exit(EXIT_FAILURE);
}
memShare = shmat(shmid, NULL, 0);
while(1)
{
memShare->ordre = randomC();
printf("Memoire mise a jour.\nVal->\n\tordre : %c\n\n", memShare->ordre);
usleep(999999);
}
}

View File

@ -0,0 +1,36 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/shm.h>
#include <sys/ipc.h>
typedef struct {
float temp;
int press;
char ordre;
}uneStruct;
int main()
{
int shmid, loop = 0;
char *shm;
uneStruct *sharedStruct;
key_t clef;
clef = ftok("/tmp/bidon", 1234);
shmid = shmget(clef, sizeof(uneStruct), IPC_CREAT | 0666);
if(shmid < 0)
{
perror("Erreur shmget");
exit(EXIT_FAILURE);
}
sharedStruct = shmat(shmid, NULL, 0);
while(1)
{
loop++;
printf("Loop %d\t|%d\t|%f\t| %c\n", loop, sharedStruct->temp, sharedStruct->press, sharedStruct->ordre);
usleep(999999);
}
return 0;
}

47
Deuxieme annee/popen.c Normal file
View File

@ -0,0 +1,47 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define BUFSIZ 255
int main()
{
int nbOctets;
int descTube[2];
int descTube2[2];
char chaine[] = "Salut papa!";
char buffer[BUFSIZ];
pid_t pid;
memset(buffer, '\0', BUFSIZ);
if ( pipe(descTube) == 0 && pipe(descTube2) == 0)
{
pid = fork(); // duplication du processus
if (pid == -1) // oups un probleme
{
fprintf(stderr, "Pb de fork");
exit(EXIT_FAILURE);
}
else // fork ok
{
if (pid == 0) // je suis dans le process fils
{
nbOctets = read(descTube[0], buffer, BUFSIZ);
nbOctets = write(descTube2[1], chaine, strlen(chaine));
printf("%d octets ecrits\n", nbOctets);
printf("octets lus: %d: %s\n", nbOctets, buffer);
exit(EXIT_SUCCESS);
}
else //je suis dans le process pere
{
strcpy(chaine, "test");
nbOctets = write(descTube[1], chaine, strlen(chaine));
nbOctets = read(descTube2[0], buffer, BUFSIZ);
printf("%d octets ecrits\n", nbOctets);
printf("octets lus: %d: %s\n", nbOctets, buffer);
}
}
}
exit(EXIT_SUCCESS);
}

View File

@ -0,0 +1,101 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <string.h>
#include <errno.h>
#include <arpa/inet.h>
#include <unistd.h>
#define BACKLOG 5
int main()
{
fd_set rfds;
struct timeval tv;
int retval;
struct sockaddr_in infoServer;
struct sockaddr_in retourServer;
socklen_t tailleRetourServ;
int retourSocket;
int retourBind;
int retourListen;
int retourAccept;
int retourRead;
int retourWrite;
int msg;
infoServer.sin_family = AF_INET;
infoServer.sin_addr.s_addr = htonl(INADDR_ANY);
infoServer.sin_port = htons(3434);
FD_ZERO(&rfds);
FD_SET(0, &rfds);
tv.tv_sec = 5;
tv.tv_usec = 0;
retval = select(1, &rfds, NULL, NULL, &tv);
retourSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if(retourSocket == -1)
{
printf("Erreur socket\n");
printf("%s", strerror(errno));
exit(errno);
}
retourBind = bind(retourSocket, (struct sockaddr *)&infoServer, sizeof(infoServer));
if(retourBind == -1)
{
printf("Erreur bind\n");
printf("%s", strerror(errno));
exit(errno);
}
retourListen = listen(retourSocket, BACKLOG);
if(retourListen == -1)
{
printf("Erreur listen\n");
printf("%s", strerror(errno));
exit(errno);
}
tailleRetourServ = sizeof(retourServer);
retourAccept = accept(retourSocket, (struct sockaddr *)&retourServer, &tailleRetourServ);
if(retourAccept == -1)
{
printf("Erreur accept\n");
printf("%s", strerror(errno));
exit(errno);
}
retourRead = read(retourAccept, &msg, sizeof(msg));
if(retourRead == -1)
{
printf("Erreur recv\n");
printf("%s", strerror(errno));
exit(errno);
}
printf("%d", msg);
msg = -msg;
retourWrite = write(retourAccept, &msg, sizeof(msg));
if(retourWrite == -1)
{
printf("Erreur sendto\n");
printf("%s", strerror(errno));
exit(errno);
}
return 0;
}

View File

@ -0,0 +1,80 @@
#include <sys/types.h>
#include <sys/shm.h>
#include <sys/ipc.h>
#include <errno.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include "semtools.h"
typedef struct
{
float temp;
int press;
char ordre;
} uneStruct;
float randomF()
{
return ((float)100.0*(rand()/(RAND_MAX+0.1)));
}
int randomI()
{
return ((int)100.0*(rand()/(RAND_MAX+0.1)));
}
int main()
{
uneStruct *memShare;
int shmid;
key_t clef;
void *shm;
clef = ftok("/tmp/bidon", 5678);
shmid = shmget(clef, sizeof(uneStruct), 0666);
if(shmid < 0)
{
perror("Erreur shmget");
exit(EXIT_FAILURE);
}
//debut sem
id_sem = semget (5678, 1, IPC_CREAT | 0600);
if (id_sem == -1)
{
printf("Probleme semget : %s\n", strerror(errno));
if(errno != EEXIST)
{
exit(errno);
}
}
if(fixe_valeursem() == 0)
{
exit(0);
}
//fin init sem
memShare = shmat(shmid, NULL, 0);
while(1)
{
if(P() == 1)
{
memShare->press = randomI();
memShare->temp = randomF();
printf("Memoire mise a jour.\nVal->\n\tpress : %d, temp : %f\n\n", memShare->press, memShare->temp);
if(V() == 0)
{
exit(EXIT_FAILURE);
}
}
else
{
exit(EXIT_FAILURE);
}
usleep(999999);
}
}

View File

@ -0,0 +1,56 @@
/******************************************************
Fichier : semtools.c
Boite a outils pour manipuler des semaphores
******************************************************/
#include "semtools.h"
int fixe_valeursem(){
union semun sem_union;
sem_union.val = 1;
int retour = 1;
printf("id_sem dans fixe_valeur = %d\n",id_sem);
if (semctl(id_sem,0,SETVAL,/*sem_union*/1) == -1){
printf("impossible de creer le semaphore\n%s\n",strerror(errno));
retour = 0;
}
return(retour);
}
void supp_valeursem(){
union semun sem_union;
if (semctl(id_sem,0,IPC_RMID,sem_union) == -1){
printf("impossible de supprimer le semaphore\n%s\n",strerror(errno));
}
}
int P(){
struct sembuf sem_b;
int retour = 1;
sem_b.sem_num = 0;
sem_b.sem_op = -1; //P()
sem_b.sem_flg = SEM_UNDO ;
if (semop(id_sem,&sem_b,1) == -1){
printf("echec semaphore P()\n%s\n",strerror(errno));
retour = 0 ;
}
return(retour);
}
int V(){
struct sembuf sem_b;
int retour=1;
sem_b.sem_num = 0;
sem_b.sem_op = 1; //V()
sem_b.sem_flg = SEM_UNDO ;
if (semop(id_sem,&sem_b,1) == -1){
printf("echec semaphore V()\n%s\n",strerror(errno));
retour = 0 ;
}
return(retour);
}

View File

@ -0,0 +1,39 @@
/******************************************************
Fichier : semtools.h
Boite a outils pour manipuler des semaphores
******************************************************/
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#ifndef _SEMTOOLS_H
#define _SEMTOOLS_H
// identifiant de semaphore
int id_sem;
// fixe la valeur du sempahore
int fixe_valeursem();
// supprime le semaphore
void supp_valeursem();
// modification de la valeur du semaphore de -1 (attente)
int P();
// modification de la valeur du semaphore de 1 (sem dispo)
int V();
#if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
/* l'union semun est définie par l'inclusion de <sys/sem.h> */
#else
/* d'après X/OPEN il faut la définir nous-mêmes */
union semun {
int val; /* valeur pour SETVAL */
struct semid_ds *buf; /* buffer pour IPC_STAT, IPC_SET */
unsigned short *array; /* table pour GETALL, SETALL */
/* Spécificité Linux : */
struct seminfo *__buf; /* buffer pour IPC_INFO */
};
#endif
#endif

View File

@ -0,0 +1,75 @@
#include <sys/types.h>
#include <sys/shm.h>
#include <sys/ipc.h>
#include <errno.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include "semtools.h"
typedef struct
{
float temp;
int press;
char ordre;
} uneStruct;
char randomC()
{
return ((char)126.0*(rand()/(RAND_MAX+0.1)));
}
int main()
{
uneStruct *memShare;
int shmid;
key_t clef;
void *shm;
clef = ftok("/tmp/bidon", 5678);
shmid = shmget(clef, sizeof(uneStruct), 0666);
if(shmid < 0)
{
perror("Erreur shmget");
exit(EXIT_FAILURE);
}
//debut sem
id_sem = semget (5678, 1, IPC_CREAT | 0600);
if (id_sem == -1)
{
printf("Probleme semget : %s\n", strerror(errno));
if(errno != EEXIST)
{
exit(errno);
}
}
if(fixe_valeursem() == 0)
{
exit(0);
}
//fin init sem
memShare = shmat(shmid, NULL, 0);
while(1)
{
if(P() == 1)
{
memShare->ordre = randomC();
printf("Memoire mise a jour.\nVal->\n\tordre : %c\n\n", memShare->ordre);
if(V() == 0)
{
exit(EXIT_FAILURE);
}
}
else
{
exit(EXIT_FAILURE);
}
usleep(999999);
}
}

View File

@ -0,0 +1,56 @@
/******************************************************
Fichier : semtools.c
Boite a outils pour manipuler des semaphores
******************************************************/
#include "semtools.h"
int fixe_valeursem(){
union semun sem_union;
sem_union.val = 1;
int retour = 1;
printf("id_sem dans fixe_valeur = %d\n",id_sem);
if (semctl(id_sem,0,SETVAL,/*sem_union*/1) == -1){
printf("impossible de creer le semaphore\n%s\n",strerror(errno));
retour = 0;
}
return(retour);
}
void supp_valeursem(){
union semun sem_union;
if (semctl(id_sem,0,IPC_RMID,sem_union) == -1){
printf("impossible de supprimer le semaphore\n%s\n",strerror(errno));
}
}
int P(){
struct sembuf sem_b;
int retour = 1;
sem_b.sem_num = 0;
sem_b.sem_op = -1; //P()
sem_b.sem_flg = SEM_UNDO ;
if (semop(id_sem,&sem_b,1) == -1){
printf("echec semaphore P()\n%s\n",strerror(errno));
retour = 0 ;
}
return(retour);
}
int V(){
struct sembuf sem_b;
int retour=1;
sem_b.sem_num = 0;
sem_b.sem_op = 1; //V()
sem_b.sem_flg = SEM_UNDO ;
if (semop(id_sem,&sem_b,1) == -1){
printf("echec semaphore V()\n%s\n",strerror(errno));
retour = 0 ;
}
return(retour);
}

View File

@ -0,0 +1,39 @@
/******************************************************
Fichier : semtools.h
Boite a outils pour manipuler des semaphores
******************************************************/
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#ifndef _SEMTOOLS_H
#define _SEMTOOLS_H
// identifiant de semaphore
int id_sem;
// fixe la valeur du sempahore
int fixe_valeursem();
// supprime le semaphore
void supp_valeursem();
// modification de la valeur du semaphore de -1 (attente)
int P();
// modification de la valeur du semaphore de 1 (sem dispo)
int V();
#if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
/* l'union semun est définie par l'inclusion de <sys/sem.h> */
#else
/* d'après X/OPEN il faut la définir nous-mêmes */
union semun {
int val; /* valeur pour SETVAL */
struct semid_ds *buf; /* buffer pour IPC_STAT, IPC_SET */
unsigned short *array; /* table pour GETALL, SETALL */
/* Spécificité Linux : */
struct seminfo *__buf; /* buffer pour IPC_INFO */
};
#endif
#endif

View File

@ -0,0 +1,66 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/shm.h>
#include <sys/ipc.h>
#include "semtools.h"
typedef struct
{
float temp;
int press;
char ordre;
} uneStruct;
int main()
{
int shmid, loop = 0;
uneStruct *sharedStruct;
key_t clef;
clef = ftok("/tmp/bidon", 5678);
shmid = shmget(clef, sizeof(uneStruct), IPC_CREAT | 0666);
if(shmid < 0)
{
perror("Erreur shmget");
exit(EXIT_FAILURE);
}
//debut sem
id_sem = semget (5678, 1, IPC_CREAT | 0600);
if (id_sem == -1)
{
printf("pb semget: %s\n",strerror(errno));
if (errno!=EEXIST)
{
exit(errno);
}
}
if ( fixe_valeursem()== 0)
{
exit ( 0 );
}
//fin init sem
sharedStruct = shmat(shmid, NULL, 0);
while(1)
{
if(P() == 1)
{
printf("Loop %d\t|%d\t|%f\t| %c\n", loop, sharedStruct->temp, sharedStruct->press, sharedStruct->ordre);
if(V() == 0)
{
exit(EXIT_FAILURE);
}
}
else
{
exit(EXIT_FAILURE);
}
loop++;
usleep(999999);
}
return 0;
}

View File

@ -0,0 +1,56 @@
/******************************************************
Fichier : semtools.c
Boite a outils pour manipuler des semaphores
******************************************************/
#include "semtools.h"
int fixe_valeursem(){
union semun sem_union;
sem_union.val = 1;
int retour = 1;
printf("id_sem dans fixe_valeur = %d\n",id_sem);
if (semctl(id_sem,0,SETVAL,/*sem_union*/1) == -1){
printf("impossible de creer le semaphore\n%s\n",strerror(errno));
retour = 0;
}
return(retour);
}
void supp_valeursem(){
union semun sem_union;
if (semctl(id_sem,0,IPC_RMID,sem_union) == -1){
printf("impossible de supprimer le semaphore\n%s\n",strerror(errno));
}
}
int P(){
struct sembuf sem_b;
int retour = 1;
sem_b.sem_num = 0;
sem_b.sem_op = -1; //P()
sem_b.sem_flg = SEM_UNDO ;
if (semop(id_sem,&sem_b,1) == -1){
printf("echec semaphore P()\n%s\n",strerror(errno));
retour = 0 ;
}
return(retour);
}
int V(){
struct sembuf sem_b;
int retour=1;
sem_b.sem_num = 0;
sem_b.sem_op = 1; //V()
sem_b.sem_flg = SEM_UNDO ;
if (semop(id_sem,&sem_b,1) == -1){
printf("echec semaphore V()\n%s\n",strerror(errno));
retour = 0 ;
}
return(retour);
}

View File

@ -0,0 +1,39 @@
/******************************************************
Fichier : semtools.h
Boite a outils pour manipuler des semaphores
******************************************************/
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#ifndef _SEMTOOLS_H
#define _SEMTOOLS_H
// identifiant de semaphore
int id_sem;
// fixe la valeur du sempahore
int fixe_valeursem();
// supprime le semaphore
void supp_valeursem();
// modification de la valeur du semaphore de -1 (attente)
int P();
// modification de la valeur du semaphore de 1 (sem dispo)
int V();
#if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
/* l'union semun est définie par l'inclusion de <sys/sem.h> */
#else
/* d'après X/OPEN il faut la définir nous-mêmes */
union semun {
int val; /* valeur pour SETVAL */
struct semid_ds *buf; /* buffer pour IPC_STAT, IPC_SET */
unsigned short *array; /* table pour GETALL, SETALL */
/* Spécificité Linux : */
struct seminfo *__buf; /* buffer pour IPC_INFO */
};
#endif
#endif

View File

@ -0,0 +1,46 @@
#include "socketBibli.h"
int main()
{
int socket;
int choix;
socket = demarrage();
while(1)
{
printf("Type de donner a transmettre :\n");
printf("1- Int\n");
printf("2- Float\n");
printf("3- Char\n");
printf("Choix : ");
scanf("%d", &choix);
switch (choix)
{
case 1 :
printf("Demarrage reussi, en attente de donnees.\n");
dialogueInt(socket);
break;
case 2 :
printf("Demarrage reussi, en attente de donnees.\n");
dialogueFloat(socket);
break;
case 3 :
printf("Demarrage reussi, en attente de donnees.\n");
dialogueChar(socket);
break;
default :
printf("Reponse non conforme.");
break;
}
}
return 0;
}

View File

@ -0,0 +1,111 @@
#include "socketBibli.h"
void mort(char *cituation)
{
printf("Erreur avec le dernier paquet recu, probleme %s : %s \n", cituation, strerror(errno));
}
int demarrage()
{
struct sockaddr_in infoServer;
int retourSocket;
int port;
printf("Port sur lequel vous voulez lancer le serveur :");
scanf("%d", &port);
infoServer.sin_family = AF_INET;
infoServer.sin_addr.s_addr = htonl(INADDR_ANY);
infoServer.sin_port = htons(port);
retourSocket = socket(AF_INET, SOCK_DGRAM, 0);
if(retourSocket == -1)
{
mort("demarrage socket");
}
if(bind(retourSocket, (struct sockaddr *)&infoServer, sizeof(infoServer)) == -1)
{
mort("bind");
}
return retourSocket;
}
void dialogueInt(int socket)
{
struct sockaddr_in infoClient;
int infoClientTaille;
int retourMsg;
int retourSendTo;
while(1)
{
if(recvfrom(socket, &retourMsg, sizeof(retourMsg), 0, (struct sockaddr *)&infoClient, &infoClientTaille) == -1)
{
mort("recvfrom");
exit(errno);
}
printf("%d\n", retourMsg);
if(sendto(socket, &retourMsg, sizeof(retourMsg), 0, (struct sockaddr *)&infoClient, sizeof(infoClient))==-1)
{
mort("sendto");
exit(errno);
}
}
}
void dialogueFloat(int socket)
{
struct sockaddr_in infoClient;
int infoClientTaille;
float retourMsg;
while(1)
{
if(recvfrom(socket, &retourMsg, sizeof(retourMsg), 0, (struct sockaddr *)&infoClient, &infoClientTaille) == -1)
{
mort("recvfrom");
exit(errno);
}
printf("%f\n", retourMsg);
if(sendto(socket, &retourMsg, sizeof(retourMsg), 0, (struct sockaddr *)&infoClient, sizeof(infoClient))==-1)
{
mort("sendto");
exit(errno);
}
}
}
void dialogueChar(int socket)
{
struct sockaddr_in infoClient;
int infoClientTaille;
char retourMsg[CHARLEN];
int retourSendTo;
while(1)
{
if(recvfrom(socket, &retourMsg, sizeof(retourMsg), 0, (struct sockaddr *)&infoClient, &infoClientTaille) == -1)
{
mort("recvfrom");
}
printf("%s\n", retourMsg);
if(sendto(socket, &retourMsg, sizeof(retourMsg), 0, (struct sockaddr *)&infoClient, sizeof(infoClient))==-1)
{
mort("sendto");
}
}
}

View File

@ -0,0 +1,22 @@
#ifndef SOCKETBIBLI_H_INCLUDED
#define SOCKETBIBLI_H_INCLUDED
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <string.h>
#include <errno.h>
#include <arpa/inet.h>
#define CHARLEN 512
void mort(char *cituation);
int demarrage();
void dialogueInt(int socket);
void dialogueChar(int socket);
void dialogueFloat(int socket);
#endif // SOCKETBIBLI_H_INCLUDED

View File

@ -0,0 +1,89 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <string.h>
#include <errno.h>
#include <arpa/inet.h>
#include <unistd.h>
#define BACKLOG 5
int main()
{
struct sockaddr_in infoServer;
struct sockaddr_in retourServer;
socklen_t tailleInfoServ;
int retourSocket;
int retourBind;
int retourListen;
int retourAccept;
int retourRead;
int retourWrite;
char html[]= "HTTP/1.0 200 OK\nContent-Length:68\nContent-Type: text/html\n\n<html><head><title>cc</title></head><body><h1>slt</h1></body></html>";
char msg[512];
infoServer.sin_family = AF_INET;
infoServer.sin_addr.s_addr = htonl(INADDR_ANY);
infoServer.sin_port = htons(8080);
retourSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if(retourSocket == -1)
{
printf("Erreur socket\n");
printf("%s", strerror(errno));
exit(errno);
}
retourBind = bind(retourSocket, (struct sockaddr *)&infoServer, sizeof(infoServer));
if(retourBind == -1)
{
printf("Erreur bind\n");
printf("%s", strerror(errno));
exit(errno);
}
retourListen = listen(retourSocket, BACKLOG);
if(retourListen == -1)
{
printf("Erreur listen\n");
printf("%s", strerror(errno));
exit(errno);
}
tailleInfoServ = sizeof(retourServer);
while(1){
retourAccept = accept(retourSocket, (struct sockaddr *)&retourServer, &tailleInfoServ);
if(retourAccept == -1)
{
printf("Erreur accept\n");
printf("%s", strerror(errno));
exit(errno);
}
retourRead = read(retourAccept, &msg, sizeof(msg));
if(retourRead == -1)
{
printf("Erreur read\n");
printf("%s", strerror(errno));
exit(errno);
}
printf("Nouvelle requete \n");
printf("IP : %s:%d", retourServer.sin_addr, retourServer.sin_port);
retourWrite = write(retourAccept, &html, sizeof(html));
if(retourWrite == -1)
{
printf("Erreur write\n");
printf("%s", strerror(errno));
exit(errno);
}
close(retourAccept);
}
return 0;
}

View File

@ -0,0 +1,50 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
// fonction de traitement du signal SIGUSR1
void traitement(int sig)
{
(void) signal(SIGUSR1, traitement);
printf("un signal SIGUSR1 ppid :%d\n", getppid());
}
int main(int argc, char *argv[])
{
int pid;
(void) signal(SIGUSR1, traitement); // rederoutage des signaux SIGUSR1
// vers la fonction traitement
pid = fork();
if (pid == -1)
{
printf("pb creation fork : %s\n", strerror(errno));
exit(1);
}
else
{
if (pid == 0) // process fils
{
printf("fils pid=%d\n", getpid());
kill(getppid(), SIGUSR1);
sleep(2); // tempo pour être certain que le fils sera
//encore vivant quand le pere lui
//enverra son signal
}
else // process principal (pere)
{
printf("pere pid=%d\n", getpid());
kill(pid, SIGUSR1);
sleep(2); // tempo pour être certain que le pere sera
//encore vivant quand le fils lui
//enverra son signal
}
}
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,71 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
void traitement(int sig)
{
(void ) signal(SIGUSR1, traitement);
printf("Un signal SIGUSR1 ppid : %d %d\n", getppid(), getpid());
}
int main(int argc, char *argv[])
{
int pid;
int pid2;
int pid2temp;
(void) signal(SIGUSR1, traitement);
pid = fork();
pid2temp = pid;
if (pid == -1)
{
printf("pb creation fork : %s\n", strerror(errno));
exit(1);
}
else
{
if (pid == 0) // process fils
{
pid2 = fork();
if(pid2 == -1)
{
printf("Pb creation fork :%s\n", strerror(errno));
exit(1);
}
else
{
if(pid2 == 0)// Process fils du fils
{
printf("fils P3 pid=%d\n", getpid());
kill(pid2temp, SIGUSR1);
sleep(2); // tempo pour être certain que le fils sera
//encore vivant quand le pere lui
//enverra son signal
}
else //process fils
{
printf("fils P2 pid=%d\n", getpid());
sleep(2); // tempo pour être certain que le fils sera
//encore vivant quand le pere lui
//enverra son signal
}
}
}
else // process principal (pere)
{
kill(pid2temp, SIGUSR1);
printf("pere pid=%d\n", getpid());
sleep(2); // tempo pour être certain que le pere sera
//encore vivant quand le fils lui
//enverra son signal
}
}
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!\n");
return 0;
}

View File

@ -0,0 +1,95 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <string.h>
#include <errno.h>
#include <arpa/inet.h>
#include <unistd.h>
#define BACKLOG 5
#define MAX 512
int main()
{
struct sockaddr_in infoServer;
struct sockaddr_in retourServer;
socklen_t tailleInfoServ;
int retourSocket;
int retourBind;
int retourListen;
int retourAccept;
int retourRead;
int retourWrite;
char msg[MAX];
infoServer.sin_family = AF_INET;
infoServer.sin_addr.s_addr = htonl(INADDR_ANY);
infoServer.sin_port = htons(3434);
retourSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if(retourSocket == -1)
{
printf("Erreur socket\n");
printf("%s", strerror(errno));
exit(errno);
}
retourBind = bind(retourSocket, (struct sockaddr *)&infoServer, sizeof(infoServer));
if(retourBind == -1)
{
printf("Erreur bind\n");
printf("%s", strerror(errno));
exit(errno);
}
retourListen = listen(retourSocket, BACKLOG);
if(retourListen == -1)
{
printf("Erreur listen\n");
printf("%s", strerror(errno));
exit(errno);
}
tailleInfoServ = sizeof(retourServer);
retourAccept = accept(retourSocket, (struct sockaddr *)&retourServer, &tailleInfoServ);
if(retourAccept == -1)
{
printf("Erreur accept\n");
printf("%s", strerror(errno));
exit(errno);
}
while(1)
{
retourRead = read(retourAccept, &msg, sizeof(msg));
if(retourRead == -1)
{
printf("Erreur read\n");
printf("%s", strerror(errno));
exit(errno);
}
printf("Nouveau message \n");
printf("IP : %s:%d: %s\n\n", inet_ntoa(retourServer.sin_addr), ntohs(retourServer.sin_port), msg);
printf("Message : ");
gets(msg);
printf("\n\n");
retourWrite = write(retourAccept, &msg, sizeof(msg));
if(retourWrite == -1)
{
printf("Erreur write\n");
printf("%s", strerror(errno));
exit(errno);
}
}
close(retourAccept);
return 0;
}

View File

@ -0,0 +1,79 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <string.h>
#include <errno.h>
#include <arpa/inet.h>
#define LEN 512
int main()
{
struct sockaddr_in infoServeur;
struct sockaddr_in infoServeurRetour;
char msg[LEN];
int infoServeurRetourTaille;
int retourSocket;
int retourConnect;
int retourRead;
int retourWrite;
int socketFd;
infoServeur.sin_addr.s_addr = inet_addr("172.18.58.93");
infoServeur.sin_family = AF_INET;
infoServeur.sin_port = htons(3434);
retourSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if(retourSocket == -1)
{
printf("Erreur socket\n");
printf("%s", strerror(errno));
exit(errno);
}
retourConnect = connect(retourSocket, &infoServeur, sizeof(infoServeur));
if(retourSocket == -1)
{
printf("Erreur connect\n");
printf("%s", strerror(errno));
exit(errno);
}
while (1)
{
printf("Message :");
gets(msg);
retourWrite = write(retourSocket, &msg, sizeof(msg), 0, (struct sockaddr *)&infoServeur, sizeof(infoServeur));
if(retourSocket == -1)
{
printf("Erreur write\n");
printf("%s", strerror(errno));
exit(errno);
}
//if(select())
//{
retourRead = read(retourSocket, &msg, sizeof(msg), 0, (struct sockaddr *)&infoServeurRetour, sizeof(infoServeurRetour));
if(retourRead == -1)
{
printf("Erreur read\n");
printf("%s", strerror(errno));
exit(errno);
}
printf("Message de %s:%d\n", inet_ntoa(infoServeur.sin_addr), ntohs(infoServeur.sin_port));
printf("%s\n", msg);
//}
}
close(retourSocket);
return 0;
}

View File

@ -0,0 +1,37 @@
#include "socketBibli.h"
int main()
{
struct sockaddr_in *infoServeur;
int retourSocket;
int choix;
retourSocket = connection(&infoServeur);
while(1)
{
printf("Donnee transferes par le serveur : \n");
printf("1- Int\n");
printf("2- Float\n");
printf("3- Char\n");
printf("Choix :");
scanf("%d", &choix);
switch (choix)
{
case 1:
dialogueInt(retourSocket, &infoServeur);
break;
case 2:
dialogueFloat(retourSocket, &infoServeur);
break;
case 3:
dialogueChar(retourSocket, &infoServeur);
break;
default:
printf("Mauvais choix");
exit(0);
}
}
return 0;
}

View File

@ -0,0 +1,104 @@
#include "socketBibli.h"
void mort(char *cituation)
{
printf("Erreur avec le dernier paquet recu, probleme %s : %s \n", cituation, strerror(errno));
}
int connection(struct sockaddr_in *infoServeur)
{
char IP[16];
int port;
int retourSocket;
printf("IP du serveur cible : ");
scanf("%s", &IP);
printf("Port du serveur cible : ");
scanf("%d", &port);
infoServeur->sin_addr.s_addr = inet_addr(IP);
infoServeur->sin_family = AF_INET;
infoServeur->sin_port = htons(port);
retourSocket = socket(PF_INET, SOCK_DGRAM, 0);
if(retourSocket==-1)
{
mort("socket");
}
return retourSocket;
}
void dialogueInt(int retourSocket, struct sockaddr_in *infoServeur)
{
int msg;
struct sockaddr_in infoServeurRetour;
int infoServeurRetourTaille;
while(1)
{
printf("Message (int) :");
scanf("%d", &msg);
if(sendto(retourSocket, &msg, sizeof(msg), 0, (struct sockaddr *)&infoServeur, sizeof(infoServeur)) == -1)
{
mort("sendto");
}
if(recvfrom(retourSocket, &msg, sizeof(msg), 0, (struct sockaddr *)&infoServeurRetour, &infoServeurRetourTaille) == -1)
{
mort("resvfrom");
}
}
}
void dialogueFloat(int retourSocket, struct sockaddr_in *infoServeur)
{
float msg;
struct sockaddr_in infoServeurRetour;
int infoServeurRetourTaille;
while(1)
{
printf("Message (float) :");
scanf("%f", &msg);
if(sendto(retourSocket, &msg, sizeof(msg), 0, (struct sockaddr *)&infoServeur, sizeof(infoServeur)) == -1)
{
mort("sendto");
}
if(recvfrom(retourSocket, &msg, sizeof(msg), 0, (struct sockaddr *)&infoServeurRetour, &infoServeurRetourTaille))
{
mort("resvfrom");
}
}
}
void dialogueChar(int retourSocket, struct sockaddr_in *infoServeur)
{
char msg[LONGCHAR];
struct sockaddr_in infoServeurRetour;
int infoServeurRetourTaille;
while(1)
{
printf("Message (float) :");
scanf("%s", &msg);
if(sendto(retourSocket, &msg, sizeof(msg), 0, (struct sockaddr *)&infoServeur, sizeof(infoServeur)) == -1)
{
mort("sendto");
}
if(recvfrom(retourSocket, &msg, sizeof(msg), 0, (struct sockaddr *)&infoServeurRetour, &infoServeurRetourTaille))
{
mort("resvfrom");
}
}
}

View File

@ -0,0 +1,22 @@
#ifndef SOCKETBIBLI_H_INCLUDED
#define SOCKETBIBLI_H_INCLUDED
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <string.h>
#include <errno.h>
#include <arpa/inet.h>
#define LONGCHAR 512
void mort(char *cituation);
int connection(struct sockaddr_in *infoServeur);
void dialogueInt(int retourSocket, struct sockaddr_in *infoServeur);
void dialogueChar(int retourSocket, struct sockaddr_in *infoServeur);
void dialogueFloat(int retourSocket, struct sockaddr_in *infoServeur);
#endif // SOCKETBIBLI_H_INCLUDED

View File

@ -0,0 +1,80 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <string.h>
#include <errno.h>
#include <arpa/inet.h>
typedef struct{
unsigned char jour;
unsigned char mois;
unsigned short int annee;
char jourDeLaSemaine[10];
}datePerso;
int main()
{
datePerso perso;
datePerso retourPerso;
struct sockaddr_in infoServeur;
struct sockaddr_in infoServeurRetour;
int infoServeurRetourTaille;
int retourSocket;
int retourConnect;
int retourRead;
int retourWrite;
int socketFd;
int retourMsg;
int msg = 8;
perso.jour = 17;
perso.mois = 12;
perso.annee = 1997;
strcpy(perso.jourDeLaSemaine, "Lundi");
infoServeur.sin_addr.s_addr = inet_addr("172.18.58.142");
infoServeur.sin_family = AF_INET;
infoServeur.sin_port = htons(5555);
retourSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if(retourSocket == -1)
{
printf("Erreur socket\n");
printf("%s", strerror(errno));
exit(errno);
}
retourConnect = connect(retourSocket, &infoServeur, sizeof(infoServeur));
if(retourSocket == -1)
{
printf("Erreur connect\n");
printf("%s", strerror(errno));
exit(errno);
}
retourWrite = write(retourSocket, &msg, sizeof(msg), 0, (struct sockaddr *)&infoServeur, sizeof(infoServeur));
if(retourSocket == -1)
{
printf("Erreur write\n");
printf("%s", strerror(errno));
exit(errno);
}
retourRead = read(retourSocket, &retourMsg, sizeof(retourMsg), 0, (struct sockaddr *)&infoServeurRetour, &infoServeurRetourTaille);
if(retourSocket == -1)
{
printf("Erreur read\n");
printf("%s", strerror(errno));
exit(errno);
}
printf("%d", retourMsg);
close(retourSocket);
return 0;
}

View File

@ -0,0 +1,88 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <string.h>
#include <errno.h>
#include <arpa/inet.h>
#include <unistd.h>
#define BACKLOG 5
int main()
{
struct sockaddr_in infoServer;
struct sockaddr_in retourServer;
socklen_t tailleRetourServ;
int retourSocket;
int retourBind;
int retourListen;
int retourAccept;
int retourRead;
int retourWrite;
int msg;
infoServer.sin_family = AF_INET;
infoServer.sin_addr.s_addr = htonl(INADDR_ANY);
infoServer.sin_port = htons(5555);
retourSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if(retourSocket == -1)
{
printf("Erreur socket\n");
printf("%s", strerror(errno));
exit(errno);
}
retourBind = bind(retourSocket, (struct sockaddr *)&infoServer, sizeof(infoServer));
if(retourBind == -1)
{
printf("Erreur bind\n");
printf("%s", strerror(errno));
exit(errno);
}
retourListen = listen(retourSocket, BACKLOG);
if(retourListen == -1)
{
printf("Erreur listen\n");
printf("%s", strerror(errno));
exit(errno);
}
tailleRetourServ = sizeof(retourServer);
retourAccept = accept(retourSocket, (struct sockaddr *)&retourServer, &tailleRetourServ);
if(retourAccept == -1)
{
printf("Erreur accept\n");
printf("%s", strerror(errno));
exit(errno);
}
retourRead = read(retourAccept, &msg, sizeof(msg));
if(retourRead == -1)
{
printf("Erreur recv\n");
printf("%s", strerror(errno));
exit(errno);
}
printf("%d", msg);
msg = -msg;
retourWrite = write(retourAccept, &msg, sizeof(msg));
if(retourWrite == -1)
{
printf("Erreur sendto\n");
printf("%s", strerror(errno));
exit(errno);
}
return 0;
}

11
Deuxieme annee/testFork.c Normal file
View File

@ -0,0 +1,11 @@
#include <stdio.h>
#include <stdlib.h>
int main()
{
fork();
fork();
fork();
printf("* ");
return 0;
}

View File

@ -0,0 +1,33 @@
#include <stdio.h>
#include <stdlib.h>
int main()
{
int pid1, pid2, pid3;
pid1 = fork();
if (pid1 == 0)
{
printf("p1\n");
}
else
{
pid2 = fork();
if (pid2 == 0)
{
printf("p2\n");
}
else
{
pid3 = fork();
if (pid3 == 0)
{
printf("p3\n");
}
else
{
printf("p4\n");
}
}
}
return 0;
}

View File

@ -0,0 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!\n");
return 0;
}

86
Deuxieme annee/threadTD.c Normal file
View File

@ -0,0 +1,86 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
typedef struct {
int v1;
int v2;
int v3;
}laStruct;
laStruct maStruct;
void *fonction_update1 ()
{
maStruct.v1 = 1;
}
void *fonction_update2 ()
{
maStruct.v2 = 2;
}
void *fonction_update3 ()
{
maStruct.v3 = 3;
}
int main()
{
int resultat;
pthread_t un_thread;
pthread_t deux_thread;
pthread_t trois_thread;
void *thread_result;
resultat = pthread_create(&un_thread, NULL, fonction_update1, NULL);
if (resultat != 0) {
perror("Thread creation failed");
exit(EXIT_FAILURE);
}
resultat = pthread_create(&deux_thread, NULL, fonction_update2, NULL);
if (resultat != 0) {
perror("Thread creation failed");
exit(EXIT_FAILURE);
}
resultat = pthread_create(&trois_thread, NULL, fonction_update3, NULL);
if (resultat != 0) {
perror("Thread creation failed");
exit(EXIT_FAILURE);
}
printf("Attente de la fin du thread...\n");
resultat = pthread_join(un_thread, &thread_result);
if (resultat != 0) {
perror("Thread join a foir... echoué");
exit(EXIT_FAILURE);
}
printf("Attente de la fin du thread...\n");
resultat = pthread_join(deux_thread, &thread_result);
if (resultat != 0) {
perror("Thread join a foir... echoué");
exit(EXIT_FAILURE);
}
printf("Attente de la fin du thread...\n");
resultat = pthread_join(trois_thread, &thread_result);
if (resultat != 0) {
perror("Thread join a foir... echoué");
exit(EXIT_FAILURE);
}
printf("%d\n%d\n%d\n", maStruct.v1, maStruct.v2, maStruct.v3);
exit(EXIT_SUCCESS);
return 0;
}

View File

@ -0,0 +1,87 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
typedef struct {
int v1;
int v2;
int v3;
}laStruct;
laStruct maStruct;
void *fonction_update1 (int val)
{
maStruct.v1 = val;
}
void *fonction_update2 (int val)
{
maStruct.v2 = val;
}
void *fonction_update3 (int val)
{
maStruct.v3 = val;
}
int main()
{
int resultat;
pthread_t un_thread;
pthread_t deux_thread;
pthread_t trois_thread;
void *thread_result;
int val[3] = {1, 3, 5};
resultat = pthread_create(&un_thread, NULL, fonction_update1, (void *) val[0]);
if (resultat != 0) {
perror("Thread creation failed");
exit(EXIT_FAILURE);
}
resultat = pthread_create(&deux_thread, NULL, fonction_update2, (void *) val[1]);
if (resultat != 0) {
perror("Thread creation failed");
exit(EXIT_FAILURE);
}
resultat = pthread_create(&trois_thread, NULL, fonction_update3, (void *) val[2]);
if (resultat != 0) {
perror("Thread creation failed");
exit(EXIT_FAILURE);
}
printf("Attente de la fin du thread...\n");
resultat = pthread_join(un_thread, &thread_result);
if (resultat != 0) {
perror("Thread join a foir... echoué");
exit(EXIT_FAILURE);
}
printf("Attente de la fin du thread...\n");
resultat = pthread_join(deux_thread, &thread_result);
if (resultat != 0) {
perror("Thread join a foir... echoué");
exit(EXIT_FAILURE);
}
printf("Attente de la fin du thread...\n");
resultat = pthread_join(trois_thread, &thread_result);
if (resultat != 0) {
perror("Thread join a foir... echoué");
exit(EXIT_FAILURE);
}
printf("%d\n%d\n%d\n", maStruct.v1, maStruct.v2, maStruct.v3);
exit(EXIT_SUCCESS);
return 0;
}

View File

@ -0,0 +1,96 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
typedef struct {
int v1;
int v2;
int v3;
}laStruct;
laStruct maStruct;
pthread_mutex_t mutex;
void *fonction_update (int val[])
{
pthread_mutex_lock(&mutex);
maStruct.v1 = val[0];
maStruct.v2 = val[1];
maStruct.v3 = val[2];
printf("Valeur en cours de Thread :\n\t%d\t%d\t%d\n\n",maStruct.v1, maStruct.v2, maStruct.v3);
pthread_mutex_unlock(&mutex);
}
int main()
{
pthread_t un_thread;
pthread_t deux_thread;
pthread_t trois_thread;
void *thread_result;
int resultat;
int valT1[3] = {1, 3, 5};
int valT2[3] = {2, 4, 6};
int valT3[3] = {10, 20, 30};
int retourMutex;
pthread_mutexattr_t mutexattr = PTHREAD_MUTEX_INITIALIZER;
retourMutex = pthread_mutex_init(&mutex, &mutexattr);
if (retourMutex != 0)
{
perror("Erreur peu probable dans l'initialisation du mutex.");
exit(EXIT_FAILURE);
}
resultat = pthread_create(&un_thread, NULL, fonction_update, (void *) valT1);
if (resultat != 0) {
perror("Thread creation failed");
exit(EXIT_FAILURE);
}
printf("Attente de la fin du thread...\n");
resultat = pthread_create(&deux_thread, NULL, fonction_update, (void *) valT2);
if (resultat != 0) {
perror("Thread creation failed");
exit(EXIT_FAILURE);
}
printf("Attente de la fin du thread...\n");
resultat = pthread_create(&trois_thread, NULL, fonction_update, (void *) valT3);
if (resultat != 0) {
perror("Thread creation failed");
exit(EXIT_FAILURE);
}
printf("Attente de la fin du thread...\n");
resultat = pthread_join(un_thread, &thread_result);
if (resultat != 0) {
perror("Thread join a foir... echoué");
exit(EXIT_FAILURE);
}
resultat = pthread_join(deux_thread, &thread_result);
if (resultat != 0) {
perror("Thread join a foir... echoué");
exit(EXIT_FAILURE);
}
resultat = pthread_join(trois_thread, &thread_result);
if (resultat != 0) {
perror("Thread join a foir... echoué");
exit(EXIT_FAILURE);
}
pthread_mutex_lock(&mutex);
printf("Val finale :\n\t%d\t%d\t%d\n", maStruct.v1, maStruct.v2, maStruct.v3);
pthread_mutex_unlock(&mutex);
exit(EXIT_SUCCESS);
return 0;
}

51
Deuxieme annee/threads.c Normal file
View File

@ -0,0 +1,51 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <sys/syscall.h>
char message[255];
typedef struct {
int v1;
int v2;
int v3;
}laStruct;
void *ma_fonction_thread(void *arg)
{
int tid = syscall(SYS_gettid);
printf("Le tid du thread est :%d\n", tid);
sleep(3);
strcpy(message, "Bye!");
pthread_exit((void *) "Merci pour le temps CPU.");
}
int main()
{
int resultat;
pthread_t un_thread;
void *thread_result;
strcpy(message, "Debian c'est cool.");
resultat = pthread_create(&un_thread, NULL, ma_fonction_thread, (void *)message);
if (resultat != 0) {
perror("Thread creation failed");
exit(EXIT_FAILURE);
}
printf("PID du programme principal : %d\n", getpid());
printf("Attente de la fin du thread...\n");
resultat = pthread_join(un_thread, &thread_result);
if (resultat != 0) {
perror("Thread join a foir... echoué");
exit(EXIT_FAILURE);
}
printf("OK, valeur de retour du Thread join :%s\n", (char *)thread_result);
printf("Le message est maintenant %s\n", message);
exit(EXIT_SUCCESS);
}

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="ExoVacances" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/ExoVacances" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/ExoVacances" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="main.c">
<Option compilerVar="CC" />
</Unit>
<Extensions>
<code_completion />
<debugger />
</Extensions>
</Project>
</CodeBlocks_project_file>

View File

@ -0,0 +1,23 @@
# depslib dependency file v1.0
1445507269 source:/home/tiji/workspace/ExoVacances/main.c
<stdio.h>
<stdlib.h>
<errno.h>
<string.h>
<sys/timeb.h>
<math.h>
<ctype.h>
<unistd.h>
<time.h>
1446709546 source:/home/USERS/ELEVES/SNIR2015/therbron/workspace/ExoVacances/main.c
<stdio.h>
<stdlib.h>
<errno.h>
<string.h>
<sys/timeb.h>
<math.h>
<ctype.h>
<unistd.h>
<time.h>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.c" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="12711" topLine="190" />
</Cursor>
<Folding>
<Collapse line="11" />
<Collapse line="40" />
<Collapse line="50" />
<Collapse line="60" />
<Collapse line="70" />
<Collapse line="83" />
<Collapse line="91" />
<Collapse line="102" />
<Collapse line="119" />
</Folding>
</File>
<EditorTabsLayout layout="06f58f90563b057300346aed00000002=*0;Pendu:main.c@layout2|name=dummy;caption=;state=2098174;dir=3;layer=0;row=0;pos=0;prop=100000;bestw=535;besth=316;minw=535;minh=316;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=06f58f90563b057300346aed00000002;caption=;state=2098172;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=200;besth=200;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|dock_size(5,0,0)=202|" />
</CodeBlocks_layout_file>

Binary file not shown.

View File

@ -0,0 +1,400 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/timeb.h>
#include <math.h>
#include <ctype.h>
#include <unistd.h>
#include <time.h>
#define TAILLEMAX 50
void formatageDate(int jour, int mois, int annee){
int choixFormatage;
do{
printf("Format d'affichage de votre date de naissance : \n");
printf("1 - jj/mm/aaaa\n");
printf("2 - jj-mm-aaaa\n");
printf("3 - jj:mm:aaaa\n");
printf("4 - jj.mm.aaaa\n");
printf("Choisissez le format d'affichage (1, 2, 3 ou 4) : ");
scanf("%d", &choixFormatage);
switch (choixFormatage){
case 1:
printf("Votre date de naissance est le %d/%d/%d.\n\n", jour, mois, annee);
break;
case 2:
printf("Votre date de naissance est le %d-%d-%d.\n\n", jour, mois, annee);
break;
case 3:
printf("Votre date de naissance est le %d:%d:%d.\n\n", jour, mois, annee);
break;
case 4:
printf("Votre date de naissance est le %d.%d.%d.\n\n", jour, mois, annee);
break;
default:
printf("La valeur entrée est incorrecte, réessayez.\n");
}
}while(choixFormatage < 1 || choixFormatage > 4);
}
int acquisitionJourNaissance(){
int jour;
do{
printf("Jour de naissance : ");
scanf("%d", &jour);
}while(jour < 1 || jour > 31);
printf("Jour correcte.\n");
return jour;
}
int acquisitionMoisNaissance(){
int mois;
do{
printf("Mois de naissance : ");
scanf("%d", &mois);
}while(mois < 1 || mois > 12);
printf("Mois correcte.\n");
return mois;
}
int acquisitionAnneeNaissance(){
int annee;
do{
printf("Année de naissance : ");
scanf("%d", &annee);
}while(annee < 1900 || annee > 2013);
printf("Année correcte.\n");
return annee;
}
void comptageMois(int jour, int mois, int annee, int tabJourMois[]){
int deroulementMois;
int nbMoisPlus30 = 0;
for(deroulementMois = 0; deroulementMois < 12; deroulementMois++){
printf("Le mois numéro %d contient %d jours.\n", deroulementMois+1, tabJourMois[deroulementMois]);
if(tabJourMois[deroulementMois] > 30){
nbMoisPlus30++;
}
}
printf("Il y a %d mois ayant plus de 30 jours dans l'année.\n\n", nbMoisPlus30);
}
void verificationDateNaissance(int jour, int mois, int tabJourMois[]){
if(jour <= tabJourMois[mois-1]){
printf("Votre date de naissance semble correcte car le mois numéro %d ne possède que %d jours.\n\n", mois, tabJourMois[mois-1]);
}else{
printf("Votre date de naissance est impossible car le mois numéro %d ne possède que %d jours.\n\n", mois, tabJourMois[mois-1]);
}
}
void affichageNomMois(int jour, int mois, int annee){
char tabNomMois[12][10] = {"Janvier", "Février", "Mars", "Avril", "Mais", "Juin", "Juillet", "Aout", "Septembre", "Octobre", "Novembre", "Décembre"};
int deroulementMois;
for(deroulementMois = 0; deroulementMois < 12; deroulementMois++){
printf("Le mois numéro %d a pour nom %s.\n", deroulementMois+1, tabNomMois[deroulementMois]);
}
printf("\n");
printf("Votre date de naissance est le %d %s %d.\n", jour, tabNomMois[mois - 1], annee);
}
void msleep(unsigned int maxTime){
struct timespec req;
struct timespec rem;
timer_t secondes = 0;
long nanoSecondes = 0;
if(maxTime>=1000){
do{
secondes++;
maxTime-=1000;
}while(maxTime>=1000);
}
nanoSecondes = maxTime*1000000;
req.tv_sec = secondes;
req.tv_nsec = nanoSecondes;
nanosleep(&req, &rem);
}
unsigned int aleatoire(unsigned int maxAlea){
struct timeb t;
float a, b;
unsigned int nbmilli;
ftime(&t);
nbmilli = t.time * 1000 + t.millitm;
srand(nbmilli);
a = rand();
b = (maxAlea * a) / RAND_MAX;
msleep(250);
return((unsigned int) b);
}
void effacerEcran(){
printf("%c[2J", 0x1B);
printf("\033[50A");
}
int comptageCaractere(char proposition[]){
int nombre;
for(nombre = 0; proposition[nombre] != 0; nombre++){}
return nombre;
}
void ecrireTextePendu(int nbCaractere, char carBon[TAILLEMAX]){
int boucle;
for(boucle = 0; boucle < nbCaractere; boucle++){
if(carBon[boucle] != '\0'){
printf("%c ", carBon[boucle]);
}else{
printf("_ ");
}
}
printf("\n");
}
char verificationPendu(char aDeviner, char proposition, char carBon){
if(aDeviner == proposition){
return aDeviner;
}else{
if(carBon != '\0'){}
else{
return '\0';
}
}
}
void dessinerPendu(int lePendu){
switch (lePendu){
case 1:
printf(" \n \n \n \n \n \n \n \n \n \n");
break;
case 2:
printf(" \n \n \n \n \n \n \n \n \n \n==================");
break;
case 3:
printf(" \n || \n || \n || \n || \n || \n ||\n ||\n ||\n ||\n==================");
break;
case 4:
printf(" \n || \n || \n || \n || \n || \n ||\n ||\n /||\n //||\n==================");
break;
case 5:
printf(" \n || / \n || / \n ||/ \n || \n || \n ||\n ||\n /||\n //||\n==================");
break;
case 6:
printf("\n ,==========Y===\n || / \n || / \n ||/ \n || \n || \n ||\n ||\n /||\n //||\n==================");
break;
case 7:
printf("\n ,==========Y===\n || / |\n || / |\n ||/ \n || \n || \n ||\n ||\n /||\n //||\n==================");
break;
case 8:
printf("\n ,==========Y===\n || / |\n || / |\n ||/ o\n || \n || \n ||\n ||\n /||\n //||\n==================");
break;
case 9:
printf("\n ,==========Y===\n || / |\n || / |\n ||/ o\n || |\n || \n ||\n ||\n /||\n //||\n==================");
break;
case 10:
printf("\n ,==========Y===\n || / |\n || / |\n ||/ o\n || /|\n || \n ||\n ||\n /||\n //||\n==================");
break;
case 11:
printf("\n ,==========Y===\n || / |\n || / |\n ||/ o\n || /|\\\n || \n ||\n ||\n /||\n //||\n==================");
break;
case 12:
printf("\n ,==========Y===\n || / |\n || / |\n ||/ o\n || /|\\\n || /\n ||\n ||\n /||\n //||\n==================");
break;
case 13:
printf("\n ,==========Y===\n || / |\n || / |\n ||/ o\n || /|\\\n || /|\n ||\n ||\n /||\n //||\n==================");
break;
}
printf("\n");
}
void exercice1(){
int jour;
int mois;
int annee;
int tabJourMois[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30 ,31};
char nom[TAILLEMAX];
char prenom[TAILLEMAX];
printf("Bienvenue dans l'exercice de synthèse !\n\n");
annee = acquisitionAnneeNaissance();
mois = acquisitionMoisNaissance();
jour = acquisitionJourNaissance();
printf("\n");
printf("Votre date de naissance est le %d/%d/%d.\n\n", jour, mois, annee);
printf("Votre nom : ");
scanf("%s", nom);
printf("Votre prénom : ");
scanf("%s", prenom);
printf("\n");
printf("Bonjour %s %s.\n", prenom, nom);
if(annee >= 1995){
printf("Désolé, vous êtes trop jeune.");
}else{
printf("Vous êtes autorisé à continuer.");
formatageDate(jour, mois, annee);
comptageMois(jour, mois, annee, tabJourMois);
verificationDateNaissance(jour, mois, tabJourMois);
affichageNomMois(jour, mois, annee);
}
}
void exercice2(){
char proposition[5];
char couleur[5] = {'r', 'r', 'v', 'b', 'b'};
int deroulementCouleur;
int nbPosBon;
int tentative = 0;
printf("Bienvenue dans le jeu MinorMind !\n\n");
printf("Arriverez vous à deviner la couleur ?\n");
do{
tentative++;
printf("Votre proposition (ex: rbvbr) : ");
scanf(" %c%c%c%c%c", &proposition[0], &proposition[1], &proposition[2], &proposition[3], &proposition[4]);
nbPosBon = 0;
if((proposition[0] == 'r' || proposition[0] == 'v' || proposition[0] == 'b')
&& (proposition[1] == 'r' || proposition[1] == 'v' || proposition[1] == 'b')
&& (proposition[2] == 'r' || proposition[2] == 'v' || proposition[2] == 'b')
&& (proposition[3] == 'r' || proposition[3] == 'v' || proposition[3] == 'b')
&& (proposition[4] == 'r' || proposition[4] == 'v' || proposition[4] == 'b')){
for(deroulementCouleur = 0; deroulementCouleur < 5; deroulementCouleur++){
if(proposition[deroulementCouleur] == couleur[deroulementCouleur]){
nbPosBon++;
}
}
printf("%d de vos couleurs sont à la bonne place.\n", nbPosBon);
}else{
printf("Saisie incorrecte.\n");
}
}while(nbPosBon < 5);
printf("Félicitations !\n");
printf("La séquence %c%c%c%c%c était la bonne !\n", couleur[0], couleur[1], couleur[2], couleur[3], couleur[4]);
printf("Vous avez réussi à trouver la bonne séquence en %d tentative(s).\n", tentative);
}
void exercice3(){
char phrasesENA[4][8][255] = {{"Mesdames, mesieurs, ", "Je reste fondamentalement persuadé que ", "Dès lors, sachez que je me battrai pour faire admettre que", "Par ailleurs, c'est en toute connaissance de cause que je peux affirmer aujourd'hui que ", "Je tiens à vous dire ici ma détermination sans faille pour clamer haut et fort que ", "J'ai depuis longtemps (ai-je besoin de vous le rappeler?), défendu l'idée que ", "Et c'est en toute conscience que je déclare avec conviction que ", "Et ce n'est certainement pas vous, mes chers compatriotes, qui me contredirez si je vous dis que "},
{"la conjoncture actuelle ", "la situation d'exclusion que certains d'entre vous connaissent ", "l'acuité des problèmes de la vie quotidienne ", "la volonté farouche de sortir notre pays de la crise ", "l'effort prioritaire en faveur de statut précaire des exclus ", "le particularisme dû à notre histoire unique ", "l'aspiration plus que légitime de chacun au progrès social ", "la nécessité de répondre à votre inquiétude journalière, que vous soyez jeunes ou âgés, ", "Je reste fondamentalement persuadé que "},
{"doit s'intégrer à la finalisation globale ", "oblige à la prise en compte encore plus effective ", "interpelle le citoyen que je suis et nous oblige tous à aller de l'avant dans la voie ", "a pour conséquence obligatoire l'urgente nécessité ", "conforte mon désir incontestable d'aller dans le sens ", "doit nous amener au choix réellement impératif ", "doit prendre en compte les préoccupations de la population de la base dans l'élaboration ", "entraine une mission somme toute des plus exaltantes pour moi : l'élaboration "},
{"d'un projet porteur de véritable espoirs, notamment pour les plus démunis.", "d'un programme plus humain, plus fraternel et plus juste.", "de solutions rapides correspondant aux grands axes sociaux prioritaies.", "d'un plan correspondant véritablement aux exigences légitimes de chacun.", "d'une valorisation sans concession de nors caractères spécifiques.", "d'une restructuration dans laquelle chacun pourra enfin retrouver sa dignité.", "d'un avenir s'orientant vers plus de progrès et plus de justice.", "d'un processus allant vers plus d'égalité."}};
int nbPhrase;
int genererPhrase;
printf("Combien de phrases voulez-vous générer ?");
scanf("%d", &nbPhrase);
for(genererPhrase = 0; genererPhrase < nbPhrase; genererPhrase++){
printf("%d :\n", genererPhrase+1);
printf("%s%s%s%s", phrasesENA[0][aleatoire(7)], phrasesENA[1][aleatoire(7)]
, phrasesENA[2][aleatoire(7)], phrasesENA[3][aleatoire(7)]);
printf("\n");
}
}
void exercice4(){
char proposition;
char carBon[TAILLEMAX];
char comparaisonCarBon[TAILLEMAX];
char aDeviner[TAILLEMAX];
int nbCaractere;
int curseur;
int lePendu = 1;
int comparaison;
printf("Bienvenue dans le jeu du pendu !\n\n");
printf("Saisir le mot à deviner :");
scanf("%s", aDeviner);
effacerEcran();
do{
printf("\nProposer une lettre :");
scanf(" %c", &proposition);
effacerEcran();
for(curseur = 0; curseur < TAILLEMAX; curseur++){
comparaisonCarBon[curseur] = carBon[curseur];
}
nbCaractere = comptageCaractere(aDeviner);
for(curseur = 0; curseur < TAILLEMAX; curseur++){
carBon[curseur] = verificationPendu(aDeviner[curseur], proposition, carBon[curseur]);
}
if(strcmp(comparaisonCarBon, carBon) == 0){
lePendu++;
printf("Votre lettre n'est pas présente dans le mot à deviner.\n");
}else{
printf("Votre lettre est bien dans le mot à deviner.\n");
}
for(curseur = 0; curseur < 50; curseur++){
comparaisonCarBon[curseur] = carBon[curseur];
}
ecrireTextePendu(nbCaractere, carBon);
dessinerPendu(lePendu);
}while((strcmp(carBon, aDeviner) != 0) && (lePendu < 13));
if(lePendu == 13){
effacerEcran();
printf("GAME OVER\n\n");
printf("Vous avez tué notre bon vieux M.Bidochon...\n");
printf("Le mot était %s.\n", aDeviner);
}else{
effacerEcran();
printf("Vous avez gagné, félicitations ! \nVous avez sauvé M.Bidochon de la pendaison.\n");
printf("\nLe mot à deviner était bien %s !\n", aDeviner);
}
}
int main()
{
int numExercice;
do{
printf("Bienvenue dans le programme d'occupation de vacances.\n");
printf("Quel exercice souhaitez-vous essayer ?\n");
printf("1 - Synthèse Septembre Octobre\n");
printf("2 - MinorMind\n");
printf("3 - Générateur de langue de bois\n");
printf("4 - Le pendu\n");
printf("Votre choix : ");
scanf("%d", &numExercice);
switch (numExercice){
case 1:
effacerEcran();
exercice1();
break;
case 2:
effacerEcran();
exercice2();
break;
case 3:
effacerEcran();
exercice3();
break;
case 4:
effacerEcran();
exercice4();
break;
default:
printf("La valeur est incorrecte, réessayez.");
}
}while(numExercice < 1 || numExercice > 4);
}

Binary file not shown.

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="IMC" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/IMC" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/IMC" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="main.c">
<Option compilerVar="CC" />
</Unit>
<Extensions>
<envvars />
<code_completion />
<debugger />
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

View File

@ -0,0 +1,5 @@
# depslib dependency file v1.0
1443519554 source:/home/USERS/ELEVES/SNIR2015/therbron/workspace/IMC/main.c
<stdio.h>
<stdlib.h>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="3831" topLine="112" />
</Cursor>
</File>
<EditorTabsLayout layout="0625df90560a5e5e001730b600000002=*0;IMC:main.c@layout2|name=dummy;caption=;state=2098174;dir=3;layer=0;row=0;pos=0;prop=100000;bestw=531;besth=265;minw=531;minh=265;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=0625df90560a5e5e001730b600000002;caption=;state=2098172;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=200;besth=200;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|dock_size(5,0,0)=202|" />
</CodeBlocks_layout_file>

Binary file not shown.

159
Premiere annee/IMC/main.c Normal file
View File

@ -0,0 +1,159 @@
//Herbron Tanguy
//Calcul de l'IMC
#include <stdio.h>
#include <stdlib.h>
int main()
{
char nom[100];
char prenom[100];
char sexe;
char choixFormule;
float age;
int menu = 0;
float taille;
float poids;
float imc;
float poidsIdeal;
printf("Bienvenue dans notre programme de calcul de l'IMC.\n");
printf("Nous avons besoin de quelques renseignements.\n");
printf("Votre nom: ");
gets(nom);
printf("Votre prénom: ");
gets(prenom);
printf("Votre sexe (h ou f): ");
scanf(" %c", &sexe);
while(sexe != 'h' && sexe != 'f')
{
printf("Saisie incorrecte, réessayez.\n");
printf("Votre sexe (h ou f): ");
scanf(" %c", &sexe);
}
printf("Votre age: ");
scanf("%d", &age);
printf("Votre taille (en mètre): ");
scanf("%f", &taille);
printf("Votre poids (en kg): ");
scanf("%f", &poids);
printf("\n");
printf("Votre fiche récapitulative :\n");
printf("- Identite : %s %s\n", prenom, nom);
printf("- Age : %.0f ans\n", age);
printf("- Poids : %.2f kg\n", poids);
printf("- Taille : %.2f m\n", taille);
//Vérification du sexe pour une écriture plus correcte
if(sexe == 'h')
{
printf("- Sexe : homme\n\n");
}
else
{
printf("- Sexe : femme\n\n");
}
imc = poids / (taille * taille);
//Correspondance de la corpulence en fonction de l'IMC
if(imc <= 16.5)
{
printf("Votre indice de masse corporelle est de %.1f.\n", imc);
printf("Votre corpulence est qualifiée de famine.\n");
}
else
{
if(imc <= 18.5)
{
printf("Votre indice de masse corporelle est de %.1f.\n", imc);
printf("Votre corpulence est qualifiée de maigreur.\n");
}
else
{
if(imc <= 25)
{
printf("Votre indice de masse corporelle est de %.1f.\n", imc);
printf("Votre corpulence est qualifiée de normale.\n");
}
else
{
if(imc <= 30)
{
printf("Votre indice de masse corporelle est de %.1f.\n", imc);
printf("Votre corpulence est qualifiée de surpoids.\n");
}
else
{
if(imc <= 35)
{
printf("Votre indice de masse corporelle est de %.1f.\n", imc);
printf("Votre corpulence est qualifiée de obésité modéré.\n");
}
else
{
if(imc <= 40)
{
printf("Votre indice de masse corporelle est de %.1f.\n", imc);
printf("Votre corpulence est qualifiée de obésité sévère.\n");
}
else
{
printf("Votre indice de masse corporelle est de %.1f.\n", imc);
printf("Votre corpulence est qualifiée de obésité morbide.\n");
}
}
}
}
}
}
printf("\n");
do
{
printf("Calculez votre poids idéal :\n");
printf("a - formule de Lorents\n");
printf("b - formule de Devine\n");
printf("c - formule de Lorents en tenant compte de l'age\n");
printf("q - quitter le menu de calcul du poids idéal\n");
printf("Votre choix: ");
scanf(" %c", &choixFormule);
//Menu pour choisir le mode de calcul du poids idéal
switch (choixFormule)
{
case 'a':
if(sexe == 'h')
{
}
printf("Votre poids idéal selon la formule de Lorents est de %.1f kg.\n\n", poidsIdeal);
break;
case 'b':
if(sexe == 'h')
{
poidsIdeal = 50 + 2.3 * (taille / 0.0254 - 60);
}
else
{
poidsIdeal = 45.5 + 2.3 * (taille / 0.0254 - 60);
}
printf("Votre poids idéal selon la formule de Devine est de %.1f kg.\n\n", poidsIdeal);
break;
case 'c':
poidsIdeal = 50 + ((taille * 100 - 150) / 4) + ((age - 20) / 4);
printf("Votre poids idéal selon la formule de Lorents en tenant compte de l'age est de %.1f kg.\n\n", poidsIdeal);
break;
case 'q':
printf("Vous avez quitté le menu de calcul du poids idéal.\n");
menu++;
break;
default:
printf("Caractère entré incorrecte. Réessayez.\n\n");
}
}
while (menu == 0);
}

Binary file not shown.

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Jeu_revolu" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/Jeu_revolu" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/Jeu_revolu" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="main.c">
<Option compilerVar="CC" />
</Unit>
<Extensions>
<envvars />
<code_completion />
<debugger />
</Extensions>
</Project>
</CodeBlocks_project_file>

View File

@ -0,0 +1,6 @@
# depslib dependency file v1.0
1442304473 source:/home/USERS/ELEVES/SNIR2015/therbron/workspace/Jeu_revolu/main.c
<stdio.h>
<stdlib.h>
<time.h>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="675" topLine="0" />
</Cursor>
</File>
<EditorTabsLayout layout="05941e9055f7f1a31eb177fe00000002=*0;TP_PI:main.c@layout2|name=dummy;caption=;state=2098174;dir=3;layer=0;row=0;pos=0;prop=100000;bestw=531;besth=265;minw=531;minh=265;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=05941e9055f7f1a31eb177fe00000002;caption=;state=2098172;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=200;besth=200;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|dock_size(5,0,0)=202|" />
</CodeBlocks_layout_file>

Binary file not shown.

View File

@ -0,0 +1,27 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
srand(time(NULL));
int aTrouver = rand() % 100;
int trouve = 0;
int userEnter, essai = 0;
while(trouve == 0){
printf("Entrer une valeur :");
scanf("%d", &userEnter);
if(userEnter < aTrouver){
printf("La valeur à trouver est plus grande.\n");
essai++;
}else{
if(userEnter > aTrouver){
printf("La valeur à trouver est plus petite.\n");
essai++;
}else{
printf("Vous avez trouvé en %d essai(s).", essai);
trouve = 1;
}
}
}
}

Binary file not shown.

View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Monayeur" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/Monayeur" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/Monayeur" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="bibliotheque_perso.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="bibliotheque_perso.h" />
<Unit filename="main.c">
<Option compilerVar="CC" />
</Unit>
<Extensions>
<envvars />
<code_completion />
<debugger />
</Extensions>
</Project>
</CodeBlocks_project_file>

View File

@ -0,0 +1,12 @@
# depslib dependency file v1.0
1447321099 source:/home/USERS/ELEVES/SNIR2015/therbron/workspace/Monayeur/bibliotheque_perso.c
<stdio.h>
<stdlib.h>
1447320423 source:/home/USERS/ELEVES/SNIR2015/therbron/workspace/Monayeur/main.c
<stdio.h>
<stdlib.h>
"bibliotheque_perso.h"
1447316403 /home/USERS/ELEVES/SNIR2015/therbron/workspace/Monayeur/bibliotheque_perso.h

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="bibliotheque_perso.c" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2552" topLine="70" />
</Cursor>
</File>
<File name="main.c" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="982" topLine="12" />
</Cursor>
</File>
<File name="bibliotheque_perso.h" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="147" topLine="0" />
</Cursor>
</File>
<EditorTabsLayout layout="062adfc0564444eb00277d1000000002=*0;Pointeur_1:main.c,1;Pointeur_1:manipPointeur.h,2;Pointeur_1:manipPointer.c@layout2|name=dummy;caption=;state=2098174;dir=3;layer=0;row=0;pos=0;prop=100000;bestw=695;besth=266;minw=695;minh=266;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=062adfc0564444eb00277d1000000002;caption=;state=2098172;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=200;besth=200;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|dock_size(5,0,0)=202|" />
</CodeBlocks_layout_file>

View File

@ -0,0 +1,100 @@
#include <stdio.h>
#include <stdlib.h>
#define DELTA 0.001
double demanderBoisson()
{
int choixBoisson;
double prixBoisson;
printf("Choisissez votre boisson :\n");
printf("1 - Café long [1.5€]\n");
printf("2 - Café cours [0.8€]\n");
printf("Votre choix :");
scanf("%d", &choixBoisson);
switch (choixBoisson){
case 1:
prixBoisson = 1.5;
break;
case 2:
prixBoisson = 0.8;
break;
}
return prixBoisson;
}
double attendrePiece(double prixBoisson, int pieceUser[])
{
int piece;
double somme = 0;
do{
printf("Le prix est de %.1f€\n", prixBoisson);
printf("Monnaie :\n");
printf("1 - 20€\n");
printf("2 - 10€\n");
printf("3 - 5€\n");
printf("4 - 2€\n");
printf("5 - 1€\n");
printf("6 - 0.5€\n");
printf("7 - 0.2€\n");
printf("8 - 0.1€\n");
printf("Piece a entrer :");
scanf("%d", &piece);
switch (piece){
case 1:
somme = somme + 20;
pieceUser[0]++;
break;
case 2:
somme = somme + 10;
pieceUser[1]++;
break;
case 3:
somme = somme + 5;
pieceUser[2]++;
break;
case 4:
somme = somme + 2;
pieceUser[3]++;
break;
case 5:
somme = somme + 1;
pieceUser[4]++;
break;
case 6:
somme = somme + 0.5;
pieceUser[5]++;
break;
case 7:
somme = somme + 0.2;
pieceUser[6]++;
break;
case 8:
somme = somme + 0.1;
pieceUser[7]++;
break;
}
printf("La somme que vous avez entree est de %.1f€\n", somme);
}while(prixBoisson > somme);
return somme - prixBoisson;
}
double rendrePiece(double rendrePrix, double valPiece[], int nbPiece[], int pieceRendu[])
{
int boucle;
// mise à jours des pieces a rendre
for(boucle = 0; boucle < 8; boucle++){
// je peux rendre des pieces de la valeur courante
if(valPiece[boucle] <= rendrePrix){
// tant que je peux rendre des pieces de la valeur courante, je le fais
while((rendrePrix > (valPiece[boucle]-DELTA)) && (nbPiece[boucle] != 0)){
rendrePrix = rendrePrix - valPiece[boucle];
pieceRendu[boucle]++;
nbPiece[boucle]--;
}
}
}
return rendrePrix;
}

View File

@ -0,0 +1,8 @@
#ifndef BIBLIOTHEQUE_PERSO_H_INCLUDED
#define BIBLIOTHEQUE_PERSO_H_INCLUDED
double demanderBoisson();
double attendrePiece(double prixBoisson, int pieceUser[]);
double rendrePiece(double rendrePrix, double valPiece[], int nbPiece[], int pieceRendu[]);
#endif // BIBLIOTHEQUE_PERSO_H_INCLUDED

Binary file not shown.

View File

@ -0,0 +1,54 @@
#include <stdio.h>
#include <stdlib.h>
#include "bibliotheque_perso.h"
int main()
{
double valPiece[8] = {20, 10, 5, 2, 1, 0.5, 0.2, 0.1};
double prixBoisson;
double valeurARendre;
int nbPiece[8] = {0, 0, 0, 5, 5, 8, 9, 12};
int pieceUser[8] = {0, 0, 0, 0, 0};
int pieceRendu[8] = {0, 0, 0, 0, 0};
int choix;
int boucle;
printf("Bonjour.\n");
do{
printf("Que voulez-vous faire ?\n");
printf("1 - Commander une boisson\n");
printf("2 - Quitter\n");
printf("Votre choix :");
scanf("%d", &choix);
switch (choix){
case 1:
prixBoisson = demanderBoisson();
valeurARendre = attendrePiece(prixBoisson, pieceUser);
printf("Somme à rendre : %.1f\n", valeurARendre);
// ajouter les pieces de l'usager dans le monnayeur
for(boucle = 0; boucle < 8; boucle++){
nbPiece[boucle] = nbPiece[boucle] + pieceUser[boucle];
}
valeurARendre = rendrePiece(valeurARendre, valPiece, nbPiece, pieceRendu);
printf("Pieces rendues :\n");
for(boucle = 0; boucle < 8; boucle++){
printf("%d piece de %.1f€\n", pieceRendu[boucle], valPiece[boucle]);
}
break;
case 2:
printf("Au revoir\n");
break;
default:
printf("Saisie incorrecte\n");
break;
}
}while(choix != 2);
return 0;
}

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Pendu" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/Pendu" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/Pendu" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="gestionPendu.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="gestionPendu.h" />
<Unit filename="main.c">
<Option compilerVar="CC" />
</Unit>
<Extensions>
<envvars />
<code_completion />
<debugger />
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

View File

@ -0,0 +1,12 @@
# depslib dependency file v1.0
1446461601 source:/home/USERS/ELEVES/SNIR2015/therbron/workspace/Pendu/main.c
<stdio.h>
<stdlib.h>
"biblioPerso.h"
1446461690 source:/home/USERS/ELEVES/SNIR2015/therbron/workspace/Pendu/gestionPendu.c
<stdio.h>
<stdlib.h>
1446461601 /home/USERS/ELEVES/SNIR2015/therbron/workspace/Pendu/gestionPendu.h

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="gestionPendu.c" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="3852" topLine="83" />
</Cursor>
</File>
<File name="main.c" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1323" topLine="13" />
</Cursor>
</File>
<File name="gestionPendu.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="430" topLine="12" />
</Cursor>
</File>
<EditorTabsLayout layout="0603d570563b1717004e4f8500000002=0;Pendu:main.c,*1;Pendu:gestionPendu.c,2;Pendu:gestionPendu.h@layout2|name=dummy;caption=;state=2098174;dir=3;layer=0;row=0;pos=0;prop=100000;bestw=535;besth=316;minw=535;minh=316;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=0603d570563b1717004e4f8500000002;caption=;state=2098172;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=200;besth=200;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|dock_size(5,0,0)=202|" />
</CodeBlocks_layout_file>

View File

@ -0,0 +1,119 @@
#include "gestionPendu.h"
int motEstTrouve(char *motATtrouver, char *motPropose){
return(strcmp(motATtrouver,motPropose));
}
int verifierLettrePropose(char *lettresProposees, int nbLettreProposee, char lettre)
{
int lettreTrouve=1;
int i;
for(i = 0; i<nbLettreProposee;i++){
/*
a completer
*/
}
return lettreTrouve;
}
//retourne une valeur entiere E[0..maxAlea[
unsigned int aleatoire( unsigned int maxAlea )
{
struct timeb t;
float a, b ;
unsigned int nbmilli;
ftime( &t );
nbmilli = t.time * 1000 + t.millitm;
srand( nbmilli );
a = rand();
b = ( maxAlea * a ) / RAND_MAX;
return( ( unsigned int )b );
}
void initialiserMot(char *motCourant,int longueurMot){
/*
a completer
*/
motCourant[longueurMot]='\0'; // pour que le tableau de caracteres devienne une chaine de caracteres
}
int afficherMenu(){
int choix;
printf("Voulez-vous jouer ?");
printf("1 - Oui");
printf("2 - Non");
scanf("%d", &choix);
if(choix == 1){
return choix;
}else{
if(choix == 2){
return -choix;
}else{
printf("Erreur");
return -choix;
}
}
}
void afficherPendu(int nroErreur){
switch (nroErreur){
case 1:
printf(" \n \n \n \n \n \n \n \n \n \n");
break;
case 2:
printf(" \n \n \n \n \n \n \n \n \n \n==================");
break;
case 3:
printf(" \n || \n || \n || \n || \n || \n ||\n ||\n ||\n ||\n==================");
break;
case 4:
printf(" \n || \n || \n || \n || \n || \n ||\n ||\n /||\n //||\n==================");
break;
case 5:
printf(" \n || / \n || / \n ||/ \n || \n || \n ||\n ||\n /||\n //||\n==================");
break;
case 6:
printf("\n ,==========Y===\n || / \n || / \n ||/ \n || \n || \n ||\n ||\n /||\n //||\n==================");
break;
case 7:
printf("\n ,==========Y===\n || / |\n || / |\n ||/ \n || \n || \n ||\n ||\n /||\n //||\n==================");
break;
case 8:
printf("\n ,==========Y===\n || / |\n || / |\n ||/ o\n || \n || \n ||\n ||\n /||\n //||\n==================");
break;
case 9:
printf("\n ,==========Y===\n || / |\n || / |\n ||/ o\n || |\n || \n ||\n ||\n /||\n //||\n==================");
break;
case 10:
printf("\n ,==========Y===\n || / |\n || / |\n ||/ o\n || /|\n || \n ||\n ||\n /||\n //||\n==================");
break;
case 11:
printf("\n ,==========Y===\n || / |\n || / |\n ||/ o\n || /|\\\n || \n ||\n ||\n /||\n //||\n==================");
break;
case 12:
printf("\n ,==========Y===\n || / |\n || / |\n ||/ o\n || /|\\\n || /\n ||\n ||\n /||\n //||\n==================");
break;
case 13:
printf("\n ,==========Y===\n || / |\n || / |\n ||/ o\n || /|\\\n || /|\n ||\n ||\n /||\n //||\n==================");
break;
}
printf("\n");
}
void afficherLettre(char *histo, int nbLettre){
int boucle;
for(boucle = 0; boucle < nbLettre; boucle++){
printf("%c", histo[nbLettre]);
}
}
int motEstTrouve(char *motATtrouver, char *motPropose){
}

View File

@ -0,0 +1,48 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <errno.h>
#include <sys/timeb.h>
#include <math.h>
#ifndef _PENDU_H_
#define _PENDU_H_
#define NB_MAX_ERREUR 7
#define NB_MAX_LETTRES_POSSIBLE 26
#define NBMOTS 5
// affiche un menu proposant de jouer ou de quitter
// recupère la réponse du joueur et retourne une valeur
// positive s'il veut jouer et négative sinon
int afficherMenu();
// affiche le pendu en fonction du nombre d'erreurs
// passee en parametre
void afficherPendu(int nroErreur);
// Affiche les lettres deja proposees
// qui se trouve dans le tableau de lettre "histo"
// le nombre de lettre etant donne par nbLettre
void afficherLettre(char *histo, int nbLettre);
// retourne 0 et le mot est trouve
int motEstTrouve(char *motATtrouver, char *motPropose);
// remplace les - par la lettre propose dans le tableau mot courant
// si la lettre fait partie du mot a trouver
// retourne 1 si aucune lettre ne correspond, et 0 sinon
int placerLettre(char *motATrouver,char *motCourant,char lettrePropose);
// retourne 0 si la lettre a deja ete propose ou si ce n'est pas une lettre
int verifierLettrePropose(char *lettresProposees, int nbLettreProposee, char lettre);
// retourne un entier compris entre 0 et maxAlea
unsigned int aleatoire( unsigned int maxAlea );
// met des - dans chaque case du tableau motCourant
void initialiserMot(char *motCourant,int longueurMot);
#endif

View File

@ -0,0 +1,65 @@
#include "gestionPendu.h"
int main(int argc, char *argv[])
{
char *listeMots[NBMOTS]={"bonjour","maison","noyau","temps","blond"};
int cptErreur=0;
int longueurMot;
char *motATrouver;
char *motCourant;
int choix,i;
char lettre;
char histo[NB_MAX_LETTRES_POSSIBLE];
int cptProposition=0;
int trouve;
do{
choix=afficherMenu();
// l'utilisateur veut jouer
if (choix>0){
// init des compteurs
cptErreur=0;
cptProposition=0;
// tirage aleatooire du mot
motATrouver=listeMots[aleatoire(NBMOTS-1)];
// init du motCourant
longueurMot=strlen(motATrouver);
motCourant=(char *)malloc(longueurMot+1);
initialiserMot(motCourant,longueurMot);
// boucle de jeu
do{
printf("%s\n",motCourant);
afficherLettre(histo,cptProposition);
// demander/redemander une lettre tant que
// le caractere saisi n'est pas une lettre
// ou a deja ete propose
do{
printf("donnez une lettre :");
scanf(" %c",&lettre);
}while(verifierLettrePropose(histo,cptProposition,lettre)==0);
// mise a jour du tableau des lettres proposees
histo[cptProposition]=lettre;
cptProposition++;
// mise a jour du compteur d'erreur
cptErreur+=placerLettre(motATrouver,motCourant,lettre);
afficherPendu(cptErreur);
trouve=motEstTrouve(motATrouver,motCourant);
}while(/* a completer*/);
// liberation de la memoire du mot courant
free(motCourant);
// affichage des messages de fin de jeu
if (trouve==0)
{
printf("bravo\n");
}
else
{
printf("Perdu le mot etait %s\n",motATrouver);
}
} // fin boucle de jeu
}while (choix!=-1);
return EXIT_SUCCESS;
}

Binary file not shown.

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Perso1" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/Perso1" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/Perso1" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="main.c">
<Option compilerVar="CC" />
</Unit>
<Extensions>
<envvars />
<code_completion />
<debugger />
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

View File

@ -0,0 +1,5 @@
# depslib dependency file v1.0
1443788614 source:/home/USERS/ELEVES/SNIR2015/therbron/workspace/Perso1/main.c
<stdio.h>
<stdlib.h>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="424" topLine="10" />
</Cursor>
</File>
<EditorTabsLayout layout="05aa69d0560e7435004ed5f300000002=*0;Perso1:main.c@layout2|name=dummy;caption=;state=2098174;dir=3;layer=0;row=0;pos=0;prop=100000;bestw=371;besth=328;minw=371;minh=328;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=05aa69d0560e7435004ed5f300000002;caption=;state=2098172;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=200;besth=200;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|dock_size(5,0,0)=202|" />
</CodeBlocks_layout_file>

Binary file not shown.

View File

@ -0,0 +1,48 @@
#include <stdio.h>
#include <stdlib.h>
int main()
{
float reel;
printf("Saisir une valeur réelle: ");
scanf("%f", &reel);
if(3.14 >= reel && reel <3.16 )
{
printf("Ok");
}
int entier;
printf("Saisir une valeur entière: ");
scanf("%d", &entier);
if(0 <= entier && entier <= 20)
{
printf("Note ok");
}
char caractere;
printf("Saisir un caractère: ");
scanf("%c", &caractere);
if('a' <= caractere && caractere <= 'z')
{
printf("C'est une lettre.");
}
else
{
printf("Ce n'est pas une lettre.");
}
char caractere;
printf("Saisir un caractère: ");
scanf("%c", &caractere);
if(('a' <= caractere && caractere <= 'z') || ('A' <= caractere && caractere <= 'Z'))
{
printf("C'est une lettre.");
}
else
{
printf("Ce n'est pas une lettre.");
}
}

Binary file not shown.

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Pointeur" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/Pointeur" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/Pointeur" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="main.c">
<Option compilerVar="CC" />
</Unit>
<Extensions>
<envvars />
<code_completion />
<debugger />
</Extensions>
</Project>
</CodeBlocks_project_file>

View File

@ -0,0 +1,5 @@
# depslib dependency file v1.0
1447417843 source:/home/USERS/ELEVES/SNIR2015/therbron/workspace/Pointeur/main.c
<stdio.h>
<stdlib.h>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<EditorTabsLayout layout="@layout2|name=dummy;caption=;state=2098174;dir=3;layer=0;row=0;pos=0;prop=100000;bestw=695;besth=266;minw=695;minh=266;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|dock_size(5,0,0)=202|" />
</CodeBlocks_layout_file>

Binary file not shown.

View File

@ -0,0 +1,25 @@
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *ptrCar;
int *ptrEntier;
float *ptrReel;
char chaine[]="12345678000A";
int i;
ptrCar = chaine ;
ptrEntier = (int *)chaine ;
ptrReel = (float *)chaine ;
for(i=0;i<3;i++)
{
printf("ptrCar = %X\t*ptrCar = %c\n",ptrCar,*ptrCar);
printf("ptrEntier = %X\t*ptrEntier = %d\n",ptrEntier,*ptrEntier);
printf("ptrReel = %X\t*ptrReel = %f\n",ptrReel,*ptrReel);
ptrCar++;
ptrEntier++;
ptrReel++;
printf("\n");
}
}

Binary file not shown.

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Pointeur_1" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/Pointeur_1" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/Pointeur_1" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="main.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="manipPointer.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="manipPointeur.h" />
<Extensions>
<envvars />
<code_completion />
<debugger />
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

View File

@ -0,0 +1,10 @@
# depslib dependency file v1.0
1447323561 source:/home/USERS/ELEVES/SNIR2015/therbron/workspace/Pointeur_1/manipPointer.c
1447326653 source:/home/USERS/ELEVES/SNIR2015/therbron/workspace/Pointeur_1/main.c
<stdio.h>
<stdlib.h>
"manipPointeur.h"
1447323860 /home/USERS/ELEVES/SNIR2015/therbron/workspace/Pointeur_1/manipPointeur.h

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.c" open="1" top="1" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="733" topLine="6" />
</Cursor>
</File>
<EditorTabsLayout layout="052053b0564d7ad0003fccb200000002=*3;Pointeur_1:main.c@layout2|name=dummy;caption=;state=2098174;dir=3;layer=0;row=0;pos=0;prop=100000;bestw=695;besth=266;minw=695;minh=266;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=052053b0564d7ad0003fccb200000002;caption=;state=2098172;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=200;besth=200;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|dock_size(5,0,0)=202|" />
</CodeBlocks_layout_file>

Binary file not shown.

View File

@ -0,0 +1,36 @@
#include <stdio.h>
#include <stdlib.h>
#include "manipPointeur.h"
int main()
{
//Little Endian
char *ptrCar;
int *ptrEntier;
float *ptrReel;
char chaine[]="12345678000A";
int i;
int val=0x01020304;
ptrCar = chaine ;
ptrEntier = (int *)chaine ;
ptrReel = (float *)chaine ;
/* for(i=0; i<3; i++)
{
printf("ptrCar = %X\t*ptrCar = %c\n",ptrCar,*ptrCar);
printf("ptrEntier = %X\t*ptrEntier = %d\n",ptrEntier,*ptrEntier);
printf("ptrReel = %X\t*ptrReel = %f\n",ptrReel,*ptrReel);
ptrCar++;
ptrEntier++;
ptrReel++;
printf("\n");
}*/
ptrCar=(char*)&val;
for(i=0; i<4; i++)
{
printf("adr : %X -> val octet : %X\n",ptrCar,*ptrCar);
ptrCar++;
}
return 0;
}

View File

View File

@ -0,0 +1,6 @@
#ifndef MANIPPOINTEUR_H_INCLUDED
#define MANIPPOINTEUR_H_INCLUDED
#endif // MANIPPOINTEUR_H_INCLUDED

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More