Link to home
Start Free TrialLog in
Avatar of matthew016
matthew016Flag for Belgium

asked on

\n\r

Hello, I'm learning how to use files in C language ,
and there's something I don't understand
- In my file :
Hello

- In my pgm :
printf("%d\n", ftell(filein));   // 0
printf("%c\n", fgetc(filein)); // H
printf("%d\n", ftell(filein));   // 1

then with a fseek i go at 5th position, just before the \n\r

printf("%d\n", ftell(filein));   // 5
printf("%c\n", fgetc(filein)); // <new line>
printf("%d\n", ftell(filein));   // 7

But I tought fgetc would only take the '\n' cause fgetc takes one char ...
Why it takes both in one time ?

Thanks.
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

I guess it is due you have opened your file as 'text', something like:

filein = fopen("yourfile.txt", "rt");

Try to open your file as binary:

filein = fopen("yourfile.txt", "rb");
ASKER CERTIFIED SOLUTION
Avatar of efn
efn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of matthew016

ASKER

Thanks, very good