// Print the last n lines of a file i.e implement your own tail command
int cnt = 0;char c;
Do not use arithmetic on file positions if file is opened in text mode. It will not give you correct result.
If file is opened in text mode, 1 character does not always mean 1 byte. And how file position is implemented (if it points to specific character or byte) is unspecified.
In your case problem is that on Windows a newline symbol is two bytes long. Text streams converts it into single-byte symbol
'\n' so you wouldn't need to worry about difference between platforms and actual byte sequences used.
So your first read reads last byte of two-byte endline symbol which happens to have same value as
'\n' in ASCII. Next read lands in the beginning of two-byte endline symbol and stream correctly converts it into