Very annoying difference between Windows and Linux

Write here if you have problems with your Java source code

Moderator: Board moderators

Post Reply
venusaur
New poster
Posts: 4
Joined: Wed Apr 23, 2003 3:05 pm

Very annoying difference between Windows and Linux

Post by venusaur » Wed Apr 23, 2003 3:50 pm

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?

turuthok
Experienced poster
Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia
Contact:

Post by turuthok » Wed Apr 23, 2003 8:05 pm

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').
The fear of the LORD is the beginning of knowledge (Proverbs 1:7).

xbeanx
Experienced poster
Posts: 114
Joined: Wed Jul 30, 2003 10:30 pm
Location: Newfoundland, Canada (St. John's)

Post by xbeanx » Fri Aug 08, 2003 10:55 pm

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]

Post Reply

Return to “Java”