Re: Why doesn't this piece of code work?

2022-05-17 Thread SvGaming via Digitalmars-d-learn
On Monday, 16 May 2022 at 22:25:23 UTC, kdevel wrote: On Monday, 16 May 2022 at 16:53:15 UTC, SvGaming wrote: [...] [...] In main your program reads an integer: ``` int n; writef("Pick an option: "); readf(" %s", ); ``` [...] Just tried the solution and it works perfectly!

Re: Why doesn't this piece of code work?

2022-05-16 Thread SvGaming via Digitalmars-d-learn
On Monday, 16 May 2022 at 22:25:23 UTC, kdevel wrote: On Monday, 16 May 2022 at 16:53:15 UTC, SvGaming wrote: [...] [...] In main your program reads an integer: ``` int n; writef("Pick an option: "); readf(" %s", ); ``` [...] Thanks for the help!

Re: Why doesn't this piece of code work?

2022-05-16 Thread Ali Çehreli via Digitalmars-d-learn
On 5/16/22 15:25, kdevel wrote: > string a; > a = readln(); > writeln(a); > consumes that newline from your first input resulting in variable a > containing the empty string ending with a newline. Great catch! I should put this combination in my chapter. > I am not sure, why %s

Re: Why doesn't this piece of code work?

2022-05-16 Thread kdevel via Digitalmars-d-learn
On Monday, 16 May 2022 at 16:53:15 UTC, SvGaming wrote: [...] https://github.com/svgaming234/ezusb forgot to post it in the previous reply, I am kind of stupid In main your program reads an integer: ``` int n; writef("Pick an option: "); readf(" %s", ); ``` but your console/Terminal

Re: Why doesn't this piece of code work?

2022-05-16 Thread SvGaming via Digitalmars-d-learn
On Monday, 16 May 2022 at 16:44:13 UTC, SvGaming wrote: On Monday, 16 May 2022 at 16:40:59 UTC, SvGaming wrote: On Sunday, 15 May 2022 at 20:06:20 UTC, kdevel wrote: On Sunday, 15 May 2022 at 15:27:32 UTC, SvGaming wrote: [...] [...] Until you post your full programm ideally in a reduced

Re: Why doesn't this piece of code work?

2022-05-16 Thread SvGaming via Digitalmars-d-learn
On Monday, 16 May 2022 at 16:40:59 UTC, SvGaming wrote: On Sunday, 15 May 2022 at 20:06:20 UTC, kdevel wrote: On Sunday, 15 May 2022 at 15:27:32 UTC, SvGaming wrote: [...] [...] Until you post your full programm ideally in a reduced form [1] everybody who is willing to help must guess

Re: Why doesn't this piece of code work?

2022-05-16 Thread SvGaming via Digitalmars-d-learn
On Sunday, 15 May 2022 at 20:06:20 UTC, kdevel wrote: On Sunday, 15 May 2022 at 15:27:32 UTC, SvGaming wrote: [...] [...] Until you post your full programm ideally in a reduced form [1] everybody who is willing to help must guess wildly what the unposted parts of your program does and how

Re: Why doesn't this piece of code work?

2022-05-15 Thread kdevel via Digitalmars-d-learn
On Sunday, 15 May 2022 at 15:27:32 UTC, SvGaming wrote: [...] It works if that code is the main function. But in the full program that is only one of the functions and is not the main function. Until you post your full programm ideally in a reduced form [1] everybody who is willing to help

Re: Why doesn't this piece of code work?

2022-05-15 Thread Ali Çehreli via Digitalmars-d-learn
On 5/15/22 08:27, SvGaming wrote: > I am so confused right now. It works if that code is the main function. > But in the full program that is only one of the functions and is not the > main function. Could it be that the main() function exits before calling that other function? You can

Re: Why doesn't this piece of code work?

2022-05-15 Thread SvGaming via Digitalmars-d-learn
On Sunday, 15 May 2022 at 12:27:45 UTC, kdevel wrote: On Sunday, 15 May 2022 at 12:19:22 UTC, SvGaming wrote: [...] [...] Install the `strace` program (I assume you are running Linux) and start your program under strace: [...] I am so confused right now. It works if that code is the main

Re: Why doesn't this piece of code work?

2022-05-15 Thread kdevel via Digitalmars-d-learn
On Sunday, 15 May 2022 at 12:19:22 UTC, SvGaming wrote: [...] This code runs as expected. Strange. It does not for me. I even tried different compilers. It simply does not ask for user input here where it is supposed to: ```d writef("Type the path to your USB drive: "); string cont = readln;

Re: Why doesn't this piece of code work?

2022-05-15 Thread SvGaming via Digitalmars-d-learn
On Sunday, 15 May 2022 at 12:13:14 UTC, kdevel wrote: On Sunday, 15 May 2022 at 11:10:41 UTC, SvGaming wrote: [...] ``` import std.stdio; import std.process; int main () { writeln("Here is a list of your mounted drives: "); auto mounts = executeShell("cat /proc/mounts | grep media");

Re: Why doesn't this piece of code work?

2022-05-15 Thread SvGaming via Digitalmars-d-learn
On Sunday, 15 May 2022 at 11:10:41 UTC, SvGaming wrote: I want to ask the user to select their USB drive by typing the mount location. For some reason that does not work and just skips over the user input part. ```d void writeusb() { writeln("Here is a list of your mounted drives: ");

Re: Why doesn't this piece of code work?

2022-05-15 Thread kdevel via Digitalmars-d-learn
On Sunday, 15 May 2022 at 11:10:41 UTC, SvGaming wrote: I want to ask the user to select their USB drive by typing the mount location. For some reason that does not work and just skips over the user input part. ```d void writeusb() { writeln("Here is a list of your mounted drives: ");

Why doesn't this piece of code work?

2022-05-15 Thread SvGaming via Digitalmars-d-learn
I want to ask the user to select their USB drive by typing the mount location. For some reason that does not work and just skips over the user input part. ```d void writeusb() { writeln("Here is a list of your mounted drives: "); auto mounts = executeShell("cat /proc/mounts |