this main is supposed to receive user input (file names, flags and a keyword), then encrypt the file according to the user input, then close the file pointers. however it goes wrong for some reason. All of the functions have been independantly tested and work but the main fails.
when i first run the program (in the while loop) it encrypts the data properly. and if i quit the while loop and restart the program it will decrypt it properly.
Although when i encrypt the data (and stay in the while loop) then try and decrypt it immediately following it fails to decrypt it properly. no idea why...?
any advice would help a lot. Final step of my project!!!
when i first run the program (in the while loop) it encrypts the data properly. and if i quit the while loop and restart the program it will decrypt it properly.
Although when i encrypt the data (and stay in the while loop) then try and decrypt it immediately following it fails to decrypt it properly. no idea why...?
Code:
int main(void)
{
char dataInput[BUFSIZE], dataOutput[BUFSIZE], keyword[BUFSIZE];
int flags[NFLAGS];
flags[QUIT] = 0;
flags[HELP] = 0;
while (flags[QUIT] != 1)
{
while (parse_user_input(dataInput, dataOutput, keyword, flags) == 0)
printf("Error: Invalid input. type h for help.\n");
if (flags[QUIT] == 1)
break;
else if (flags[HELP] == 1){
help_message(flags[HELP]);
flags[HELP] = 0;
}
else
{
FILE *fin, *fout;
if (flags[SEED] == 0){
int i;
for (i = 0; keyword[i] != NUL; ++i)
flags[SEED] = keyword[i] + 31*flags[SEED];
}
fin = open_file(dataInput, 0);
fout = open_file(dataOutput, 1);
if (fin == 0 || fout == 0)
printf("Error opening file");
else
{
ranf_start(flags[SEED]);
encrypt(fin, fout, keyword, flags[MODULO]);
fclose(fout);
fclose(fin);
}
}
}
return 0;
}
Comment