D Programming – Input

Good Day, I was to talking to little kid this morning and he was asking me what color is the best. Every time I said a color he always answered “Really? (color)?”
What’s your favorite color? Yellow
Really? Yello?

haha, his expression made his annoying answer funny.

I adapated that kid to my program here showing basic input of string in D language.

Here is my annoying kid asking for colors program:

import std.stdio;
import std.string;

int main(){
	string input = "";
	
	write("What is your favorite color? ");
	input = strip(stdin.readln());
	
	writeln("Really? ", input, "?");
	return 0;
}

Here is the output:

d-input

 

I hope you like this post. Don’t forget to leave a comment.

Thank you very much.

D – Programming (Strings)

In programming, Strings are group of characters and they are not those strands of fiber that we tie knots or tie somebody’s neck. I often introduce students to this concept by making them count the letters of their name and resite them in reverse. Quite really fun at times. 🙂

Below is a code that shows string initialization and concatenation:

import std.stdio;

int main(){
	string fname = "Mark";
	string lname = "Hay";
	
	writeln("Hello ", fname, " ", lname);
	
	return 0;
}

Here is the output:

d-strings

 

Don’t forget to leave a comment below.

Thank you very much.