X-Git-Url: https://git.llucax.com/z.facultad/75.06/jacu.git/blobdiff_plain/d69c7c58de649932f607cbfb6e7f44a1364078f5..7a58d786d9ca645f1e61a5cb4128f354ae7a80ef:/src/zerogrouping/zg.c?ds=sidebyside diff --git a/src/zerogrouping/zg.c b/src/zerogrouping/zg.c index a3ef8e2..779694f 100644 --- a/src/zerogrouping/zg.c +++ b/src/zerogrouping/zg.c @@ -22,7 +22,7 @@ * Autores: Leandro Lucarella *---------------------------------------------------------------------------- * - * $Id: vfile.c 748 2004-06-21 00:46:08Z llucare $ + * $Id$ * */ @@ -36,25 +36,19 @@ * */ -int main(int argc, char* argv[]) +int main() { - size_t pagesize = BUFSIZ; size_t len; - char* page; - char* pageout; - if (argc > 1) pagesize = atoi(argv[1]); - if (!(page = malloc(pagesize))) return 1; - if (!(pageout = malloc(pagesize/2+pagesize+1))) /* por si se expande */ + char buff[2]; + int c; + ZG zg; + zg_init(&zg); + while ((c = getchar()) != EOF) { - free(page); - return 1; + if ((len = zg_group(&zg, buff, c))) fwrite(buff, 1, len, stdout); } - while ((len = fread(page, 1, pagesize, stdin))) - { - len = zg_group(pageout, page, len); - fwrite(pageout, 1, len, stdout); - } - free(page); + /* imprimo si quedó algo en el buffer */ + if ((len = zg_group_finish(&zg, buff))) fwrite(buff, 1, len, stdout); return 0; }