Skip to content
Snippets Groups Projects
Commit c7f4694d authored by Mickael Da Silva's avatar Mickael Da Silva
Browse files

utils

parent e212021d
No related merge requests found
#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");
......
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
#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
#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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment