Just to give you some background, I am trying to write an encryption algorithmn, so the options are -e to encrypt or -d to decrypt. During the encryption process an array of characters is written to a file called asciivalue.txt and stored for later use. This part of the program appears to work fine, HOWEVER when I try to read back from the file during the decryption process the input I am getting is not what I expected. The input file contains "YYYYYNYYYY Y" but when I read from the file into the array (chartestarray) it appears as random characters i.e. smilie faces, spaces etc......
I have read other inputs/outputs in the same program using the same logic and coding and and they work perfectly, so I am really confused why this isn't working!?!
The way I am doing it at the moment is:
Hope that makes sense :(
I have read other inputs/outputs in the same program using the same logic and coding and and they work perfectly, so I am really confused why this isn't working!?!
The way I am doing it at the moment is:
Code:
FILE *asciivalue_file; asciivalue_file = fopen("asciivalue.txt","w"); fseek(asciivalue_file, 0, SEEK_SET); char chartestarray[charcount]; //Charcount is devised elsewhere and works fine int readin = 2; int i = 0; while (readin != 7) //Very crude way of repeating I know { lc = fgetc(asciivalue_file); if (lc == EOF) break; else if (lc != EOF) { chartestarray[i] = lc; i++; } }
Comment