Skip to content
Snippets Groups Projects
utils.c 1013 B
Newer Older
Mickael Da Silva's avatar
Mickael Da Silva committed
#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;
chafiol's avatar
chafiol committed
}

void initData(struct data* d){
    d->time = 0;
    d->comparison = 0;
    d->ct_fusion = 0;
    d->ct_parse = 0;
    d->write = 0;
}

void generate_tab(long* t, int nb){
    int taille_tab = 0;
    if(nb == NULL){
chafiol's avatar
chafiol committed
        taille_tab = (int)(random()+1)%100;
chafiol's avatar
chafiol committed
    }
    else{
chafiol's avatar
chafiol committed
        taille_tab = nb;
chafiol's avatar
chafiol committed
    }

    for(int i = 0; taille_tab<taille_tab; i++){
chafiol's avatar
chafiol committed

chafiol's avatar
chafiol committed
    }
Mickael Da Silva's avatar
Mickael Da Silva committed
}