digitalmars.D.learn - Array slicing
- Heinz (15/15) Dec 14 2006 Hi, i'm trying to slice an array of chars and print it to the screen but...
- Oskar Linde (5/24) Dec 14 2006 printf expects a zero terminated string. Try:
- Georg Wrede (4/25) Dec 14 2006 What is wrong is that the hello.d in samples.d STILL USES PRINTF. :-(
- Heinz (3/3) Dec 14 2006 "That gives you and thousands of others the impression that printf is a
- torhu (3/7) Dec 14 2006 writef and writefln, in std.stdio.
- Hasan Aljudy (4/25) Dec 14 2006 printf is not a part of D.
- =?UTF-8?B?QW5kZXJzIEYgQmrDtnJrbHVuZA==?= (5/7) Dec 14 2006 The C library is a part of D, so using std.c.stdio.printf
- Hasan Aljudy (6/16) Dec 14 2006 I think it's better to just say printf is not a part of D, to not
Hi, i'm trying to slice an array of chars and print it to the screen but it doesn't seems to work, here's the code: ///////////////////////////////////// import std.string; alias char[] string; int main(char[][] args) { printf("hello world\n"); string hw = "Hello_World"; printf(cast(char*)hw[0 .. 5]); return 0; } ///////////////////////////////////// What could be wrong? it just prints to the output "Hello_World". Heinz
Dec 14 2006
Heinz wrote:Hi, i'm trying to slice an array of chars and print it to the screen but it doesn't seems to work, here's the code: ///////////////////////////////////// import std.string; alias char[] string; int main(char[][] args) { printf("hello world\n"); string hw = "Hello_World"; printf(cast(char*)hw[0 .. 5]); return 0; } ///////////////////////////////////// What could be wrong? it just prints to the output "Hello_World".printf expects a zero terminated string. Try: printf(toStringz(hw[0 .. 5])); or why not use writef instead. /Oskar
Dec 14 2006
Heinz wrote:Hi, i'm trying to slice an array of chars and print it to the screen but it doesn't seems to work, here's the code: ///////////////////////////////////// import std.string; alias char[] string; int main(char[][] args) { printf("hello world\n"); string hw = "Hello_World"; printf(cast(char*)hw[0 .. 5]); return 0; } ///////////////////////////////////// What could be wrong? it just prints to the output "Hello_World". HeinzWhat is wrong is that the hello.d in samples.d STILL USES PRINTF. :-( That gives you and thousands of others the impression that printf is a natural choice for printing stuff in D.
Dec 14 2006
"That gives you and thousands of others the impression that printf is a natural choice for printing stuff in D." So, what's the real natural choice for printing stuff in D? Thanks
Dec 14 2006
Heinz wrote:"That gives you and thousands of others the impression that printf is a natural choice for printing stuff in D." So, what's the real natural choice for printing stuff in D? Thankswritef and writefln, in std.stdio. http://www.digitalmars.com/d/phobos/std_stdio.html
Dec 14 2006
printf is not a part of D. use writef instead. import std.stdio; Heinz wrote:Hi, i'm trying to slice an array of chars and print it to the screen but it doesn't seems to work, here's the code: ///////////////////////////////////// import std.string; alias char[] string; int main(char[][] args) { printf("hello world\n"); string hw = "Hello_World"; printf(cast(char*)hw[0 .. 5]); return 0; } ///////////////////////////////////// What could be wrong? it just prints to the output "Hello_World". Heinz
Dec 14 2006
Hasan Aljudy wrote:printf is not a part of D. use writef instead.The C library is a part of D, so using std.c.stdio.printf is OK as long as toStringz is used. Maybe std.stdio.writef would be easier to use, but both alternatives are valid D. --anders
Dec 14 2006
Anders F Björklund wrote:Hasan Aljudy wrote:I think it's better to just say printf is not a part of D, to not confuse new comers. If you must be politically correct, printf is a part of the C standard library, which is available through the std.c package, but its use is not recommended.printf is not a part of D. use writef instead.The C library is a part of D, so using std.c.stdio.printf is OK as long as toStringz is used. Maybe std.stdio.writef would be easier to use, but both alternatives are valid D. --anders
Dec 14 2006