diff --git a/ASR3.1/TP05 Pointeurs Signaux/a.out b/ASR3.1/TP05 Pointeurs Signaux/a.out new file mode 100755 index 0000000..cb68f32 Binary files /dev/null and b/ASR3.1/TP05 Pointeurs Signaux/a.out differ 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