Hi
I am trying to open two files in binary read mode and then XOR the contents of these files, character by chharacter, and store the results in a third file (by opening it in Binary write mode). Although i can open the two files but get a whole lot of garbage in the resultant file which is supposed to be having the XORed results. please help me.
![]()
Thanks in advance
Manu1
code:-
Code:#include<stdio.h> #include<conio.h> #include<math.h> #include<stdlib.h> void main(void) { FILE *fptr, *fptr1, *fptr2, *fptr3, *fptr4; char plain[5000], ke[5000], cipher[5000]; int i = 0, j=0, k=0, pt1[500], kt1[500]; long int ch, ch1, ch2; clrscr(); printf("\n ENTER PLAIN TEXT (PRESS ENTER TWICE TO EXIT):\n"); fptr = fopen("ptxt.txt", "w"); fflush(fptr); do { fputs(plain, fptr); fputs("\n", fptr); } while(strlen( gets(plain) ) > 0); fclose(fptr); // fflush(fptr); printf("\n ENTER KEY (PRESS ENTER TWICE TO EXIT):\n"); fptr1 = fopen("ktxt.txt", "w"); fflush(fptr1); do { fputs(ke, fptr1); fputs("\n", fptr1); } while(strlen( gets(ke) ) > 0); fclose(fptr1); //fflush(fptr1); fptr4 = fopen("ctxt.txt", "wb"); fptr2 = fopen("ptxt.txt", "rb"); fptr3 = fopen("ktxt.txt", "rb"); fflush(fptr4); while (ch = getc(fptr2) != EOF) { ch1 = getc(fptr3) != EOF; cipher[i] = ch ^ ch1; i++; fwrite(cipher, sizeof(cipher), 1, fptr4); // i = j; } /* while (ch1 = getc(fptr3) != EOF ) { kt1[k] = ch1; k++; } cipher[i] = ch ^ ch1; // i++; // putc(cipher, fptr4); i++; }*/ /* for(k=0; k<j; k++) { putc(cipher[k], fptr4); }*/ fclose(fptr2); fclose(fptr3); fclose(fptr4); // fflush(fptr4); }



LinkBack URL
About LinkBacks



