void reverseoutput(char *s, FILE *outfp)
{
    int i;
    for (i = strlen(s) - 1; i >= 0; i--)
        putc(s[i], outfp);
}

int main(int argc, char **argv)
{
    FILE *infp = stdin, *outfp = stdout;
    char buf[256];

    switch (argc) {
    default:
    case 3:
        if ((outfp = fopen(argv[2], "w")) == NULL) {
            fprintf(stderr, "connot open file: %s", argv[2]); exit(1);
        }
    case 2:
        if ((infp = fopen(argv[1], "r")) == NULL) {
            fprintf(stderr, "connot open file: %s", argv[1]); exit(1);
        }
    case 1:
        break;
    }

    while (fgets(buf, sizeof(buf), infp))
        reverseoutput(buf, outfp);

    return 0;
}