commit 43718037d26edbedeaa3ef7c77f227ec3d724ee8 Author: Super_JK Date: Sat Mar 5 22:01:37 2022 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/a.out b/a.out new file mode 100755 index 0000000..aa91c57 Binary files /dev/null and b/a.out differ diff --git a/mem.c b/mem.c new file mode 100644 index 0000000..ce6a6be --- /dev/null +++ b/mem.c @@ -0,0 +1,58 @@ +#include // p r i n t f ( . . ) +#include // EXIT_SUCCESS +#include // s i g n a l ( . . ) +#include + + +struct vector { + double *val; + int size; +}; + +struct vector * new ( unsigned int n ){ + struct vector* v = malloc(sizeof(struct vector)); + v->size = n; + v->val = calloc(n, sizeof(double)); + return v; +} + +void printVec(struct vector* v){ + printf("["); + for (int i = 0; i< v->size; i++){ + printf("%.2f,",v->val[i]); + } + printf("]"); +} + +struct vector * add ( struct vector * v , struct vector * w ){ + if (v->size != w->size) return NULL; + + struct vector *y = new(v->size); + for (int i = 0; i< v->size; i++){ + y->val[i] = v->val[i] + w->val[i]; + } + return y; +} + +struct vector * smul ( double s , struct vector * v ){ + struct vector *y = new(v->size); + for (int i = 0; i< v->size; i++){ + y->val[i] = v->val[i] * s; + } + return y; + +} + +int main ( int argc , char * argv []) { + struct vector *v = new(3); + v->val[0] = 23.0; + v->val[1] = 5.0; + + struct vector *w = new(3); + w->val[1] = 2.0; + w->val[2] = 54.0; + + + printVec(smul(3.0,add(v,w))); + return EXIT_SUCCESS ; +} diff --git a/sig.c b/sig.c new file mode 100644 index 0000000..d59fc90 --- /dev/null +++ b/sig.c @@ -0,0 +1,38 @@ +#include // p r i n t f ( . . ) +#include // EXIT_SUCCESS +#include // s i g n a l ( . . ) +#include + + +int signb = 1; + +void handler ( int signum ) { + if ( signum == SIGINT ){ + if (signb == 1 ) + printf ( "Just give me a moment.\n" ); + else if (signb == 2) + printf("I said I need a moment !\n"); + else { + printf("Fine. I’m out of here.\n"); + exit(EXIT_SUCCESS); + } + signb +=1; + } +} + +unsigned int string_length ( char string []){ + unsigned int i = 0; + while (string[i++] != '\0'); + return i-1; + +} + +int main ( int argc , char * argv []) { + signal ( SIGINT , handler ); + + while (1) { + pause(); + //printf("Waiting loop resumed .\n"); + } + return EXIT_SUCCESS ; +}