X-Git-Url: https://git.llucax.com/z.facultad/75.06/jacu.git/blobdiff_plain/77564f0b02a149dfb7e026768afe950d7e72a8e9..86626b07ef6c182f6594bc0b398b0065cefe4aed:/otros/blocksorting/main.c diff --git a/otros/blocksorting/main.c b/otros/blocksorting/main.c index 5f36f54..7028017 100644 --- a/otros/blocksorting/main.c +++ b/otros/blocksorting/main.c @@ -5,18 +5,21 @@ int main(int argc, char *argv[]) { char *data; char *salida; - unsigned long int len, i, k; + unsigned long int len, i, k, total; FILE *fp; char c; t_BlockSort *bs; -/* if (argc != 3) { - printf("Modo de uso : %s \n", argv[0]); - return 0; + if (argc == 3) { + fp = fopen(argv[1], "r"); + len = atoi(argv[2]); + } else if (argc == 2) { + fp = stdin; /*fopen(argv[1], "r");*/ + len = atoi(argv[1]); + } else { + printf("no, no\n"); + return 1; } -*/ - fp = stdin; /*fopen(argv[1], "r");*/ - len = atoi(argv[1]); data = malloc(sizeof(char)*len); salida = malloc(sizeof(char)*(len+1)); @@ -24,21 +27,27 @@ int main(int argc, char *argv[]) salida[len] = '\0'; bs = bs_create(len); - while ((c = fgetc(fp)) != EOF) { + c = fgetc(fp); + total = 0; + while (!feof(fp)) { i = 0; - while ((c!=EOF) && (i < len)) { + while ((!feof(fp)) && (i < len)) { data[i++] = c; c = fgetc(fp); + total++; } bs_solve(data, salida, bs, &k, i); /* XXX ACA SALIDA DEBERIA PASAR A LA SIGUIENTE ETAPA XXX */ - /*printf("%s -> %ld\n", salida, k);*/ - printf("%s", salida); + if (argc == 3) + printf("%s -> %ld\n", salida, k); + else + printf("%s", salida); } fclose(fp); bs_destroy(bs); + printf("Total bytes : %ld\n", total); free(data); free(salida); return 0;