initial commit

This commit is contained in:
Super_JK
2022-03-05 22:01:37 +01:00
commit 43718037d2
4 changed files with 97 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.idea

BIN
a.out Executable file

Binary file not shown.

58
mem.c Normal file
View File

@@ -0,0 +1,58 @@
#include <stdio.h> // p r i n t f ( . . )
#include <stdlib.h> // EXIT_SUCCESS
#include <signal.h> // s i g n a l ( . . )
#include <unistd.h>
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 ;
}

38
sig.c Normal file
View File

@@ -0,0 +1,38 @@
#include <stdio.h> // p r i n t f ( . . )
#include <stdlib.h> // EXIT_SUCCESS
#include <signal.h> // s i g n a l ( . . )
#include <unistd.h>
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. Im 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 ;
}