On Nov 10, 6:03 pm, "ozgun.harmanci" <ozgun.harma...@gmail.comwrote:
I had a big problem with line returns and carriage character
difference in windows and linux. I think what happened was, the scp
program i am using in to send file from windows machine to a linux
machine did not somehow realize that the files i am uploading are
ascii files and sent them as binary. When I tried to use those files,
input to another program, in linux I was getting strange problems with
them until i realized that the line returns and carriages were the
problem.
Is there a way in C++ to determine and tell the user that the line
returns and carriages are compatible with linux or windows to warn
them against input problems? Specifically i am looking for ansi c
function to accomplish this in a robust way so as to have the input
validation correctly set.
When reading a Windows file on Unix, you will usually see an
additional '\r' in front of every new line. Just ignore it.
(If you are reading text, it counts as white space---isspace(
'\r' ) returns true in all the locales I've used---, so in a lot
of cases, it will be ignored automatically.
When reading a Unix file under Windows, you formally have an
illegal text format, which could cause istream to report an
error. In practice, the implementations I've used all treat an
LF which is not preceded by a CR as if it were, and read Unix
files without problems. (This is not the case with some
programs, however. I don't know what compiler they were
compiled with.)
There used to be two programs, unix2dos and dos2unix, under
Unix, which would convert the files "after the fact", if you
ended up with the wrong type. I don't seem to have them on my
Linux here at home, however. Of course, they'd be very easy to
write, as long as you read and write in binary (so that you
control the representation of line endings). But that doesn't
help much in practice, since most of the time, such problems
occur because of a shared file system.
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34