X-Git-Url: https://git.llucax.com/z.facultad/75.06/jacu.git/blobdiff_plain/1be06ef7e219504dbdc7b31d461e95ed3ca72bbd..86626b07ef6c182f6594bc0b398b0065cefe4aed:/otros/blocksorting/main.c diff --git a/otros/blocksorting/main.c b/otros/blocksorting/main.c index 3df6d8a..7028017 100644 --- a/otros/blocksorting/main.c +++ b/otros/blocksorting/main.c @@ -5,39 +5,49 @@ 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 = fopen(argv[1], "r"); - len = atoi(argv[2]); - data = malloc(sizeof(char)*len); salida = malloc(sizeof(char)*(len+1)); 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); + 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;