diff --git a/Algos_1/main.c b/Algos_1/main.c index b4d743eec34ddaa5fca979b4949f2eb7fb52e502..2ded197fdeafb033b077216d0bc9129fec255e42 100644 --- a/Algos_1/main.c +++ b/Algos_1/main.c @@ -1,39 +1,8 @@ #include "triInsertion.h" #include "triFusion.h" #include "triRapide.h" +#include "utils.h" - -int readToTab(long* tab, char* file){ - int n = 0; - int fd = open(file, O_RDONLY); - if(fd == -1){ - perror("open"); - exit(1); - } - char tmp[1000]; - memset(tmp, 0, 1000); - char temp; - size_t j = 0, x=0; - read(fd,&temp,sizeof(char)); - - while(temp != '.'){ - if(temp != ' '){ - tmp[x] = temp; - x++; - - } - else if(temp == ' '){ - long t = atol(tmp); - tab[j] = t; - memset(tmp, 0, 1000); - j++; - x=0; - n++; - } - read(fd,&temp,sizeof(char)); - } - return n-1; -} int main(int argc, char **argv){ if(argc!=3){ printf("Usage: ./tri <option> <input.txt>\n"); diff --git a/Algos_1/makefile b/Algos_1/makefile index 6a8fd56396c42df8c68c6c65c546ed2837cda787..abccfb855565a981837f3913ea267b234b711e54 100644 --- a/Algos_1/makefile +++ b/Algos_1/makefile @@ -1,7 +1,7 @@ all: tri -tri: main.c triInsertion.o triFusion.o triRapide.o - gcc -Wall main.c triInsertion.o triFusion.o triRapide.o -Wall -o tri +tri: main.c triInsertion.o triFusion.o triRapide.o utils.o + gcc -Wall main.c triInsertion.o triFusion.o triRapide.o utils.o -Wall -o tri insertion: triInsertion.c triInsertion.h gcc -c triInsertion.c triInsertion.h -Wall @@ -12,5 +12,8 @@ fusion: triFusion.c triFusion.h rapide: triRapide.c triRapide.h gcc -c triRapide.c triRapide.h -Wall +utils: utils.c utils.h + gcc -c utils.c utils.h -Wall + clear: rm *.o \ No newline at end of file diff --git a/Algos_1/utils.c b/Algos_1/utils.c new file mode 100644 index 0000000000000000000000000000000000000000..6ab72866f727293ff042a8f4dab8d0a48fd995c5 --- /dev/null +++ b/Algos_1/utils.c @@ -0,0 +1,33 @@ +#include "utils.h" + +int readToTab(long* tab, char* file){ + int n = 0; + int fd = open(file, O_RDONLY); + if(fd == -1){ + perror("open"); + exit(1); + } + char tmp[1000]; + memset(tmp, 0, 1000); + char temp; + size_t j = 0, x=0; + read(fd,&temp,sizeof(char)); + + while(temp != '.'){ + if(temp != ' '){ + tmp[x] = temp; + x++; + + } + else if(temp == ' '){ + long t = atol(tmp); + tab[j] = t; + memset(tmp, 0, 1000); + j++; + x=0; + n++; + } + read(fd,&temp,sizeof(char)); + } + return n-1; +} \ No newline at end of file diff --git a/Algos_1/utils.h b/Algos_1/utils.h new file mode 100644 index 0000000000000000000000000000000000000000..18fe28782fc6ac8c5f5b9ee6c7a7cfa7c4e080e2 --- /dev/null +++ b/Algos_1/utils.h @@ -0,0 +1,11 @@ +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <fcntl.h> +#include <string.h> + +int readToTab(long* tab, char* file); \ No newline at end of file