I've got this program that looks like this:
CODE
#include <stdio.h>
#include <string.h>
#include <ctype.h>
char convert( char );
int main () {
char line[96], *line_ptr, output[96];
int index, lines_processed, punct_chars;
lines_processed = 0;
punct_chars = 0;
for( lines_processed = 0; 1; ++lines_processed ) {
printf( "Input a line> " );
line_ptr = fgets( line, 96, stdin );
if( line_ptr != line || line_ptr[0] == EOF ) break;
for( index = 0; index < 96; ++index ) {
if( ispunct( (int)line_ptr[index] ) ) ++punct_chars;
output[index] = convert( line_ptr[index] );}
printf( "%s%s", line_ptr, output );
}
printf( "\n%d lines processed, %d punctuation characters.\n", lines_processed, punct_chars );
return 0;
}
char convert( char input ) {
if( ((int)input >= 'A' && (int)input < 'Y') || ((int)input >= 'a' && (int)input < 'y') ) { input+= 2;}
else if( (int)input == 'Y' || (int)input == 'Z' || (int)input == 'y' || (int)input == 'z' ) { input-= 24;}
if( (int)input == '(' ) { input+= 1;}
else if( (int)input == ')' ) { input-= 1;}
if( (int)input == '[' || (int)input == '{' || (int)input == '<' ) { input+= 2;}
else if( (int)input == ']' || (int)input == '}' || (int)input == '>' ) { input-= 2;}
return input;
}
My TA is going to use indirection to input a sample code that has the opposite of what my code will do to it, done to it (if my code is a ROT2 encryption, his is written is ROT-2). So it'll look something like this:
CODE
./my-code < his-code.c
He wants the code output to stdout (his file) so he can compile it and see if it actually works. It obviously reads from stdin through indirection, but how do I get what would normally output to the screen (stdout) to output to the file through indirection?
For example, if I do this:
CODE
./my-code < his-code.c > his-code.c
All I get output is the last line printed to the screen in the main function, the "number of lines processed" line, in his-code.c. I need the whole converted code to actually compile. Any help?