/* * swapbytes.c -- swap pairs of bytes in every group of 4 */ #include #include main(int argc, char **argv) { int i = 0, c[4]; if (argc <= 1) while ( (c[0] = getchar()) != EOF && (c[1] = getchar()) != EOF && (c[2] = getchar()) != EOF && (c[3] = getchar()) != EOF ) { putchar(c[3]); putchar(c[2]); putchar(c[1]); putchar(c[0]); i +=4; } else if (argc == 1) { /* file name supplied */ printf("cannot do files for now, using stdin\n"); } else { printf("usage: swapbytes [filename]\n"); } fprintf(stderr," %d bytes processed\n",i); }