/* * SPDsoft 98 * Replacement for the SunOS 4.x rev(1) * rev - reverse the order of characters in each line * rev [ filename ] ... */ #include int main(int argc, char **argv) { char str[2048]; int i, j; FILE *f; if (argc == 1) argc++; for( argv++ ; argc > 1; argv++, argc--) { if ( *argv == NULL ) f=stdin; else if ( NULL == ( f=fopen(*argv, "r"))) perror(*argv); if ( f != NULL ) { fgets(str,sizeof(str),f); while (!feof(f)) { if (str[0] != 0) { i = strlen(str) - 2; j = 0; while (j < i) { str[j] ^= str[i]; str[i] ^= str[j]; str[j++] ^= str[i--]; } } fputs(str,stdout); fgets(str,sizeof(str),f); } fclose(f); } } exit (0); }