August 02, 2010 Re: Doubled newlines | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | It makes sense now. Thanks. :)
Steven Schveighoffer Wrote:
> On Sat, 31 Jul 2010 23:10:05 -0400, Andrej Mitrovic <andrej.mitrovich@gmail.com> wrote:
>
> > Oh and I'm getting the same issue in Python when using CR only. I don't know why I have the CR option in the text editor if it doesn't work properly. I guess CR is used on the Macs maybe..?
> >
> > Andrej Mitrovic Wrote:
> >
> >> I'm getting normal newlines here (XP):
> >>
> >> C:\output>test.exe
> >> import std.file: readText;
> >> import std.stdio: write;
> >> void main() {
> >> string s = readText("test.d");
> >> write(s);
> >> }
> >>
> >> The text used CR+LF newlines. I also tried them using LF newlines, which worked fine. But I've then tried with CR and that gives out weird output like so:
> >>
> >> } write(s);= readText("test.d");
>
> CR means carriage return. This is for old-style line printers. When you sent a CR, it means, literally, move the carriage back to the front of the line. When you sent a LF (line feed), it means, feed the paper another line.
>
> If you printed a file to such a printer with just line feeds, you would see:
>
> import std.file: readText;
> import std.stdio: write;
> void main() {
> ...
>
>
> If you printed the file with just CRs, you would see all the lines super-imposed over eachother, because the paper is never moved, just the carriage is returned.
>
> This is the effect you are seeing, each line is super-imposed over the other. However, on a terminal, you don't see the residual letters from previously printed lines, they are completely overwritten.
>
> Essentially, if you put in a sleep between printing each line, what you'd see is this:
>
> import std.file: readText;
>
> .. pause ..
>
> import std.stdio: write;t;
>
> .. pause ..
>
> void main() {dio: write;t;
>
> ....
>
> Hope this helps ;)
>
> -Steve
|
August 03, 2010 Re: Doubled newlines | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | == Quote from bearophile (bearophileHUGS@lycos.com)'s article > I think there is a bug here, but can you please try it a bit? > The name of this program is "test.d", so it loads its souce code: > import std.file: readText; > import std.stdio: write; > void main() { > string s = readText("test.d"); > write(s); > } > On windows the output is: > import std.file: readText; > import std.stdio: write; > void main() { > string s = readText("test.d"); > write(s); > } > So it shows extra newlines (on Windows newlines are two chars). > On Windows a similar Python program doesn't show the doubled newlines: > s = open("test.d").read() > print s > Bye, > bearophile By the way, your code works correctly on my computer. I ran the program in cygwin using a bash shell under Windows XP. What doesn't work correctly in this setup is writef() followed by user input. I need to add stdout.flush() after writef. So go figure... $ dmd --help Digital Mars D Compiler v2.047 Copyright (c) 1999-2010 by Digital Mars written by Walter Bright Documentation: http://www.digitalmars.com/d/2.0/index.html $ ./readlines.exe import std.file: readText; import std.stdio: write; void main() { string s = readText( "readlines.d"); write(s); } |
Copyright © 1999-2021 by the D Language Foundation