I have this code:
while( (cCurrent = fgetc(fp)) != EOF)
{
}
The problem is, when it hits a new line it stops reading.
What would be a good way to ignore the newline character?
Edit:
I'm trying to create a file crypter. It is able to encrypt the file, but the decrypt process won't work. It works till the end of the first line, but it won't continue to the next characters in the file.
For example, for the text file:
Foo
Bar
After the encryption the result is:
Xu||Gb|t
After the decryption the result is:
FooRqb
I concluded that the new line char was the problem. maybe it wasn't.
My code is:
/* check if the file is openable */
if( (fp = fopen(szFileName, "r+")) != NULL )
{
/* save current position */
currentPos = ftell(fp);
/* get the current byte and check if it is EOF, if not then loop */
while( (cCurrent = fgetc(fp)) != EOF)
{
/* XOR it */
cCurrent ^= 0x10;
/* take the position indicator back to the last position before read byte */
fseek(fp, currentPos, SEEK_SET);
/* set the current byte */
fputc(cCurrent, fp);
/* reset stream for next read operation */
fseek(fp, 0L, SEEK_CUR);
/* save current position */
currentPos = ftell(fp);
}