Xor.c

From meaning
Jump to: navigation, search
/* xor.c -- XOR two files together and get a third -- by glenn (1995-05-11) */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main( int argc , char *argv[] )
{
	FILE *in1, *in2, *out;
	int ch1;
	int ch2;

/* Silly Error Checking Stuff */
if (argc < 3 )
{
	fprintf (stderr, "Usage: %s input-file-1 input-file-2 output-file\n", argv[0]);
	exit(1);
}

if (((in1 = fopen(argv[1], "r")) == NULL ) || ((in2 = fopen(argv[2], "r")) == NULL ) || ((out = fopen(argv[3], "w")) == NULL))
{
	fprintf(stderr, "Error opening files.\n");
	exit(2);
}
/* End of Silly Error Checking Stuff */

while (((ch1 = getc(in1)) != EOF) && ((ch2 = getc(in2)) != EOF))
	putc(ch1^ch2, out);

/* More Error Checking Stuff and THE END */

if (fclose(in1) !=0 || fclose(in2) || fclose(out) !=0)
	fprintf(stderr,"Error closing files\n");

return 0;

}

Site Information
Personal tools