www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - char e string em linguagem D

reply dark777 <jeanzonta777 yahoo.com.br> writes:
Pessoal eu fiz o seguinte programa em C++.

https://pastebin.com/CvVv6Spn

porem tentei fazer o equivalente em D mas nao entendi muito bem...

https://pastebin.com/2xw9geRR

alguem poderia me ajudar?
Jul 13
parent reply crimaniak <crimaniak gmail.com> writes:
On Thursday, 13 July 2017 at 21:49:40 UTC, dark777 wrote:
 Pessoal eu fiz o seguinte programa em C++.

 https://pastebin.com/CvVv6Spn

 porem tentei fazer o equivalente em D mas nao entendi muito 
 bem...

 https://pastebin.com/2xw9geRR

 alguem poderia me ajudar?
Se acepta utilizar intervalos en lugar de punteros desnudos. (Hola, soy traductor de google) import std.stdio, std.string; //https://www.vivaolinux.com.br/script/GNU-que-bacana class GnuQueBacana { this(){} char[] stalman() { return cast(char[])` ((__-^^-,-^^-__)) *---*******---* *--|o o|--* \ / ): :( (o_o) - https://www.gnu.org `; } char[] torvald() { return cast(char[])` ##### ####### ##O#O## ####### ##\#/## #lllllllllll## #lllllllllllll## #lllllllllllll### ##llllllllllll### OOO#llllllllll#OOO OOOOOO#llllll#OOOOOO OOOOOOO#llllll#OOOOOOO OOOOOOO######OOOOOOO https://www.kernel.org `; } string stallman() { return ` ((__-^^-,-^^-__)) *---*******---* *--|o o|--* \ / ): :( (o_o) - https://www.gnu.org `; } string torvalds() { return ` ##### ####### ##O#O## ####### ##\#/## #lllllllllll## #lllllllllllll## #lllllllllllll### ##llllllllllll### OOO#llllllllll#OOO OOOOOO#llllll#OOOOOO OOOOOOO#llllll#OOOOOOO OOOOOOO######OOOOOOO https://www.kernel.org `; } }; void main() { GnuQueBacana gnu = new GnuQueBacana(); writeln(gnu.stalman(), gnu.torvald(), gnu.stallman(), gnu.torvalds()); }
Jul 13
next sibling parent reply Basile B. <b2.temp gmx.com> writes:
On Thursday, 13 July 2017 at 22:30:29 UTC, crimaniak wrote:
 On Thursday, 13 July 2017 at 21:49:40 UTC, dark777 wrote:
   char[] stalman()
   {
       return cast(char[])`
                   ((__-^^-,-^^-__))
                    *---*******---*
                     *--|o   o|--*
                        \     /
                         ): :(
                         (o_o)
                           -
                  https://www.gnu.org

 `;
   }
Never cast a literal to char[]. modifying the resulting char[] will lead to AV, at least under linux. `.dup` the literal if you really needs char[].
Jul 13
parent crimaniak <crimaniak gmail.com> writes:
On Thursday, 13 July 2017 at 22:36:47 UTC, Basile B. wrote:
       return cast(char[])`
...
 Never cast a literal to char[]. modifying the resulting char[] 
 will lead to AV, at least under linux.  `.dup` the literal if 
 you really needs char[].
Hmm, yes, my bad. Probably, it was necessary even for this simple example to write const char[].
Jul 14
prev sibling parent dark777 <jeanzonta777 yahoo.com.br> writes:
On Thursday, 13 July 2017 at 22:30:29 UTC, crimaniak wrote:
 On Thursday, 13 July 2017 at 21:49:40 UTC, dark777 wrote:
 Pessoal eu fiz o seguinte programa em C++.

 https://pastebin.com/CvVv6Spn

 porem tentei fazer o equivalente em D mas nao entendi muito 
 bem...

 https://pastebin.com/2xw9geRR

 alguem poderia me ajudar?
Se acepta utilizar intervalos en lugar de punteros desnudos. (Hola, soy traductor de google) import std.stdio, std.string; //https://www.vivaolinux.com.br/script/GNU-que-bacana class GnuQueBacana { this(){} char[] stalman() { return cast(char[])` ((__-^^-,-^^-__)) *---*******---* *--|o o|--* \ / ): :( (o_o) - https://www.gnu.org `; } char[] torvald() { return cast(char[])` ##### ####### ##O#O## ####### ##\#/## #lllllllllll## #lllllllllllll## #lllllllllllll### ##llllllllllll### OOO#llllllllll#OOO OOOOOO#llllll#OOOOOO OOOOOOO#llllll#OOOOOOO OOOOOOO######OOOOOOO https://www.kernel.org `; } string stallman() { return ` ((__-^^-,-^^-__)) *---*******---* *--|o o|--* \ / ): :( (o_o) - https://www.gnu.org `; } string torvalds() { return ` ##### ####### ##O#O## ####### ##\#/## #lllllllllll## #lllllllllllll## #lllllllllllll### ##llllllllllll### OOO#llllllllll#OOO OOOOOO#llllll#OOOOOO OOOOOOO#llllll#OOOOOOO OOOOOOO######OOOOOOO https://www.kernel.org `; } }; void main() { GnuQueBacana gnu = new GnuQueBacana(); writeln(gnu.stalman(), gnu.torvald(), gnu.stallman(), gnu.torvalds()); }
muito massa nao achei que era tao simples assim..
Jul 13