I wanted to know how text is formatted while reading to and writing from a file. So I tried the following code on a g++ compiler. Also, I am using the < bits/stdc++.h > library.
while(!feof(fptr)) { //fptr is the pointer to the input file
int i = fgetc(fptr);
printf("%c - %d\n",i,i);
}
The input file contains the following text.
spaces
and newlines
The output I got was this.
s - 115
p - 112
a - 97
c - 99
e - 101
s - 115
- 32
- 10
a - 97
n - 110
d - 100
- 32
n - 110
e - 101
w - 119
l - 108
i - 105
n - 110
e - 101
s - 115
� - -1
I understand the last line was because of the EOF, which wasn't a character.
But why is there an empty line in the output?