Noob questions
0x10001
changdoelee at gmail.com
Thu May 2 00:51:38 UTC 2019
On Thursday, 25 April 2019 at 02:39:22 UTC, Andre Pany wrote:
> On Wednesday, 24 April 2019 at 22:44:17 UTC, 0x10001 wrote:
>> Hello, i've hit some roadblocks while trying to learn D, i'll
>> try to explain each of them below :
>>
>> [...]
>
> Regarding question 1, I had the same question some days ago
> https://forum.dlang.org/thread/akootxwiopsltifwdwxh@forum.dlang.org
>
> For question 2, can you show your complete coding? It should
> work, I assume there might be a subtitle issue in your logic.
>
> Kind regards
> Andre
Your workaround with " %s\n" worked perfectly, thank you! i
wasn't able to reproduce the second issue however despite the
source file not having changed since, if i encounter it again
i'll try to do what Erinaceus said.(Well i already did but since
i wasn't able to re-reproduce the problem it prints the same two
ubyte arrays.)
On Friday, 26 April 2019 at 09:04:26 UTC, Erinaceus wrote:
> In case you have not solved the 3rd problem yet (your code is
> almost there),
> it can be fixed by replacing this line:
> rawfile.écrire(uncompress(efile_buf2)); // alias for
> std.file.write
> with this one:
> (filename ~ ".out").écrire(uncompress(efile_buf2));
>
> The lines that open files using std.stdio.File are not needed
> and can be removed:
> File efile = File(filename, "r");
> File rawfile = File(filename ~ ".out", "w");
>
> std.file.write works pretty much like this:
> void write(string filename, void[] writeThis) {
> import std.stdio;
> File f = File(filename, "w");
> f.rawWrite(writeThis);
> f.close();
> }
>
> It expects a filename as an argument (not a std.stdio.File
> structure representing an open file). std.file.read also
> expects a filename, your code is calling that one correctly.
> Using std.stdio.File is not necessary here because
> std.file.read/write open and close the files on their own.
>
>
> About your 2nd problem: its hard to tell whats going on without
> more complete code. You may want to inspect the problematic
> string using something like this:
> string correct = "test.txt";
> string tricky = std.string.strip(readln());
> writeln("c: ", cast(ubyte[]) correct);
> writeln("t: ", cast(ubyte[]) tricky);
>
> This is going to print numeric codes of all bytes in the string
> and reveal any potentially invisible characters (like spaces,
> line-ending markers, tabs etc.), like this:
> c: [116, 101, 115, 116, 46, 116, 120, 116]
> t: [116, 101, 115, 116, 46, 116, 120, 116, 13]
The changes you proposed worked, and thank you for your
explanation, i can't reproduce my second problem anymore but here
is the original code anyway :
>
>import std.stdio;
>import std.file;
>void main() {
> writeln();
> string filename = strip(readln());
> File file = File(filename, "r");
> File ofile = File((filename ~ ".out"), "w");
> if (exists(filename)) {
> writeln("success : ","'", filename, "'");
> } else writeln("bad");
>}
More information about the Digitalmars-d-learn
mailing list