Page 1 of 1

Very annoying difference between Windows and Linux

Posted: Wed Apr 23, 2003 3:50 pm
by venusaur
In windows, "\r\n" means new line while "\n" in Linux

Because of that, At first time I got some of [WA] signal when I posted my JAVA program.

In Windows, I have to change readln() just like this
[java]while(lg<len)
{
car=System.in.read();
if(lg==0&&(car=='\r')||(car=='\n')) continue;
if((car<0)||(car=='\r')||(car=='\n')) break;
lin[lg++]+=car;
}
[/java]
But in Linux and Online judge, that code produced [WA], and I have to change to original readln().

Is there any way to make these change automacally?

Posted: Wed Apr 23, 2003 8:05 pm
by turuthok
Have you tried cygwin ???

I got the same problem months back, I installed cygwin that includes vi and gcc ... The problem went away since ...

PS: And the vi can recognize if it's DOS format or not (extra '\r' before '\n').

Posted: Fri Aug 08, 2003 10:55 pm
by xbeanx
Another way is to use the trim() method of the String class

[java]
while(lg<len)
{
car=System.in.read();
if(lg==0&&(car=='\r')||(car=='\n')) continue;
if((car<0)||(car=='\r')||(car=='\n')) break;
lin[lg++]+=car;
}

... return new String(lin).trim();
[/java]