matthew016
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, very good
filein = fopen("yourfile.txt", "rt");
Try to open your file as binary:
filein = fopen("yourfile.txt", "rb");