From 2b2cc8ccd68f76912aa851c9e15361d8dec97664 Mon Sep 17 00:00:00 2001 From: lefevre Date: Mon, 15 Nov 2021 17:44:02 +0100 Subject: [PATCH] save --- ASR3.1/TP05 Pointeurs Signaux/a.out | Bin 0 -> 16584 bytes ASR3.1/TP05 Pointeurs Signaux/exo0.c | 58 +++++++++++++++++++ ASR3.1/TP05 Pointeurs Signaux/exo1/exo1.c | 29 ++++++++++ ASR3.1/TP05 Pointeurs Signaux/exo1/helpers.c | 19 ++++++ ASR3.1/TP05 Pointeurs Signaux/exo1/helpers.h | 6 ++ 5 files changed, 112 insertions(+) create mode 100755 ASR3.1/TP05 Pointeurs Signaux/a.out create mode 100644 ASR3.1/TP05 Pointeurs Signaux/exo0.c create mode 100644 ASR3.1/TP05 Pointeurs Signaux/exo1/exo1.c create mode 100644 ASR3.1/TP05 Pointeurs Signaux/exo1/helpers.c create mode 100644 ASR3.1/TP05 Pointeurs Signaux/exo1/helpers.h diff --git a/ASR3.1/TP05 Pointeurs Signaux/a.out b/ASR3.1/TP05 Pointeurs Signaux/a.out new file mode 100755 index 0000000000000000000000000000000000000000..cb68f32d419329996595108d92f0ca19e846e5a4 GIT binary patch literal 16584 zcmeHOdu$xV8J|1b#1wqzgoK(<$TcL$3G&5;#5F}BcaG0lSI(n}4WR{=v+rzQxfge9 zY9pYI+(f;aE2dIQB~S%_RjoutX{+*R#W`+)v{D;VmC~0m2-Gv>Va!9OCAt2-+4;_U z%eg|RYX8}>cE9<4-(zOJo!Oi5&U_`*+wFF_1g9EtwIFV~(L@4Dpk1jlAOX=K8gRc@ zTqMo{Un? z{gtW*QW?>McIy6vRhJiOUjPvoGOng z$CF}0SBGkcodzJI6p(iz>~>?y&Q80OK2s`#(xF$3$j2$~fU@)Xq#I$UTn8tZq~gz1g;#8g#|GNBZ;MA-;<4oDSj$*PdrSLve>Ua6TvmbV)ryPy z)Si9)!aX4hgt5I#xFmlzFiLL4vz&C-;-avV{T{Dt-&Z$H{_yaYpTu80zT=7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hpBPC&A`Tre*-{7fLj0n literal 0 HcmV?d00001 diff --git a/ASR3.1/TP05 Pointeurs Signaux/exo0.c b/ASR3.1/TP05 Pointeurs Signaux/exo0.c new file mode 100644 index 0000000..0477e57 --- /dev/null +++ b/ASR3.1/TP05 Pointeurs Signaux/exo0.c @@ -0,0 +1,58 @@ +#include +#include +#include + + + +/*La fonction map permet de parcourir le tableau. */ +void map(void *base,size_t n ,size_t size_elem,void(*f)(void *)){ + int i; + char *ptr = (char*)base; + for(i=0;i un pointeur sur un tableau de caractère +} + + +int cmp_string (const void* a, const void* b) { + const char* *ia = (const char* *)a; + const char* *ib = (const char* *)b; + + return strcmp(*ia, *ib); +} + + + +int main(){ + + int t1[10]={12,-7,1,-16,3,19,7,1,5,0}; + char * t2[]={"chou","joujou","bijou","genou", + "caillou","hibou","pou"}; + + map(t1,10,sizeof(int),print_int); + printf("\n"); + map(t2,7,sizeof(char*),print_string); + printf("\n"); + qsort(t1,10,sizeof(int),cmp_int); + map(t1,10,sizeof(int),print_int); + printf("\n"); + qsort(t2,7,sizeof(char *),cmp_string); + map(t2,7,sizeof(char*),print_string); + printf("\n"); + +} diff --git a/ASR3.1/TP05 Pointeurs Signaux/exo1/exo1.c b/ASR3.1/TP05 Pointeurs Signaux/exo1/exo1.c new file mode 100644 index 0000000..e00cba4 --- /dev/null +++ b/ASR3.1/TP05 Pointeurs Signaux/exo1/exo1.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include +#include +#include +#include "helpers.h" + +uint64_t tirs=0, + tirs_in=0; + +double pi=0, + t1; + +int main(int argc,char * argv[]){ + + double x, + y; + t1 = tstamp(); + alarm(5); + + while(1){ + + x = ((double)rand())/(double)RAND_MAX; + y = ((double)rand())/(double)RAND_MAX; + tirs ++; + if (x*x+y*y<=1) tirs_in ++; + } +} diff --git a/ASR3.1/TP05 Pointeurs Signaux/exo1/helpers.c b/ASR3.1/TP05 Pointeurs Signaux/exo1/helpers.c new file mode 100644 index 0000000..61da3a0 --- /dev/null +++ b/ASR3.1/TP05 Pointeurs Signaux/exo1/helpers.c @@ -0,0 +1,19 @@ +#include "helpers.h" +#include +#include + + +int set_signal_handler(int signo, void (*handler)(int)) { + struct sigaction sa; + sa.sa_handler = handler; // call `handler` on signal + sigemptyset(&sa.sa_mask); // don't block other signals in handler + sa.sa_flags = SA_RESTART; // restart system calls + return sigaction(signo, &sa, NULL); +} + +double tstamp(void) { + struct timespec tv; + clock_gettime(CLOCK_REALTIME, &tv); + return tv.tv_sec + tv.tv_nsec * 1.0e-9; +} + diff --git a/ASR3.1/TP05 Pointeurs Signaux/exo1/helpers.h b/ASR3.1/TP05 Pointeurs Signaux/exo1/helpers.h new file mode 100644 index 0000000..ccb4cc5 --- /dev/null +++ b/ASR3.1/TP05 Pointeurs Signaux/exo1/helpers.h @@ -0,0 +1,6 @@ +#ifndef _HELPERS_H +#define _HELPERS_H +int set_signal_handler(int signo, void (*handler)(int)); +double tstamp(void); + +#endif \ No newline at end of file