#include "algos.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++; n++; } else if(temp == ' '){ long t = atol(tmp); tab[j] = t; memset(tmp, 0, 1000); j++; x=0; } read(fd,&temp,sizeof(char)); } return n-1; } int main(int argc, char **argv){ if(argc!=3){ printf("Usage: ./tri <option> <input.txt>\n"); exit(1); } long tab[100]; int n = readToTab(tab, argv[2]); printf("Base : "); for(int i = 0; i<n; i++){ printf("%ld,", tab[i]); } printf("\n"); if((strcmp(argv[1], "--insertion") == 0)){ triInsertion(tab, n); printf("Insertion : "); for(int i = 0; i<n; i++){ printf("%ld,", tab[i]); } printf("\n"); } else if((strcmp(argv[1], "--fusion")== 0)){ triFusion(tab, n); printf("Fusion : "); for(int i = 0; i<n; i++){ printf("%ld,", tab[i]); } printf("\n"); } else if((strcmp(argv[1], "--rapide")== 0)){ triRapide(tab, n); printf("Rapide : "); for(int i = 0; i<n; i++){ printf("%ld,", tab[i]); } printf("\n"); } else{ printf("Usage: ./tri <option> <input.txt>\n"); } return 0; }