Hi Salem
Thanks a lot for your help.
I can create both files perfectly now, but im still getting the same type of abnormal data when i access the third file (which is supposed to have XORed data from both the files instead. Pl. help me with this. Following is my amended code:
Code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
int 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");
while(fgets(plain, sizeof(plain),stdin)!= NULL)
{
if(plain[0]=='\n')
break;
fputs(plain, fptr);
fputs("\n", fptr);
}
fclose(fptr);
printf("\n ENTER KEY (PRESS ENTER TWICE TO EXIT):\n");
fptr1 = fopen("ktxt.txt", "w");
while(fgets(ke, sizeof(ke),stdin)!= NULL)
{
if(ke[0]=='\n')
break;
fputs(ke, fptr1);
fputs("\n", fptr1);
}
fclose(fptr1);
fptr4 = fopen("ctxt.txt", "wb");
fptr2 = fopen("ptxt.txt", "rb");
fptr3 = fopen("ktxt.txt", "rb");
while(ch = fgets(plain, sizeof(plain),stdin)!= NULL)
{
if(ch1 = fgets(ke, sizeof(ke),stdin)!= NULL)
{ cipher[i] = ch ^ ch1;}
i++;
fwrite(cipher, sizeof(cipher), 1, fptr4);
}
fclose(fptr2);
fclose(fptr3);
fclose(fptr4);
}
I shall be very grateful for this help.
Regards
Manu
I have tried to improve the listing of the program so as to make it more simple to read. Your help will be highly appreciated.
Thanks & regards
Manu