#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); } size_t j = 0, x=0, count = 1, sizet = 1000, nb_size = 1; char* tmp = malloc(sizeof(char)*sizet); memset(tmp, 0, 1000); char temp; read(fd,&temp,sizeof(char)); while(temp != '.'){ // printf("n:%d j:%d nb_size:%d\n", n,j,nb_size); if(temp != ' '){ tmp[x] = temp; x++; } else if(temp == ' '){ long t = atol(tmp); tab[j] = t; printf("char:%c long:%d n:%d j:%d nb_size:%d, size:%d\n",temp,tab[j], n,j,nb_size, sizet); memset(tmp, 0, sizet*nb_size); j++; count++; x=0; n++; } read(fd,&temp,sizeof(char)); if(n==sizet*nb_size){ nb_size+=1; printf("size:%d nb_size:%d, sizef:%d\n", sizet, nb_size, sizeof(char)*(sizet*nb_size)); tmp = realloc(tmp, sizeof(char)*(sizet*nb_size)); } } return n-1; } void initData(struct data* d){ d->time = 0; d->comparison = 0; d->ct_fusion = 0; d->ct_parse = 0; d->write = 0; } long* generate_tab(size_t max, size_t length){ if(length==0){ return 0; } long* tab = malloc(sizeof(long)*length); memset(tab, 0, sizeof(long)*length); size_t index = 0; for(index = 0; index<length; index++){ long p = (long)(rand()%max); tab[index] = p; } return tab; } void printData(struct data d){ printf("Time passed : %ld\n", d.time); printf("Number of comparison : %ld\n", d.comparison); printf("Number of write : %ld\n", d.write); printf("Call of fusion : %ld\n", d.ct_fusion); printf("Call of parsing : %ld\n", d.ct_parse); }