/* encodetext.c - Don Yang (uguu.org) Given text data in stdin, generate BF program that will output the same text data. 09/03/04 */ #include int main(int argc, char **argv) { FILE *infile, *outfile; int i, i0; if( argc > 1 ) { if( (infile = fopen(argv[1], "rb")) == NULL ) return printf("Can not open %s\n", argv[1]); if( argc > 2 ) { if( (outfile = fopen(argv[2], "wb+")) == NULL ) { (void)fclose(infile); return printf("Can not create %s\n", argv[2]); } } else { outfile = stdout; } } else { infile = stdin; outfile = stdout; } for(i0 = 0; (i = fgetc(infile)) != EOF;) { for(; i0 < i; i0++) (void)fputc('+', outfile); for(; i0 > i; i0--) (void)fputc('-', outfile); (void)fputc('.', outfile); } (void)fputc('\n', outfile); (void)fclose(infile); (void)fclose(outfile); return 0; }