D - I don't know much...
- Carlos (14/14) May 01 2002 Hi. I'm 100% new in D, but I know C/C++. I've been reviewing the help an...
- Walter (10/24) May 01 2002 the
- Carlos (11/39) May 01 2002 How am I supposed to do the string reading? I've tried everything. This ...
- Walter (8/17) May 01 2002 should
- Russell Borogove (6/33) May 02 2002 Ack, that 'taint right, is it? s is uninitialized there,
- Walter (4/12) May 03 2002 scanf initializes the pointer.
- Russell Borogove (12/25) May 03 2002 Not in standard C:
- Walter (3/28) May 03 2002 Oops! You're right. Yet another reason to use D!
- Russell Borogove (4/6) May 04 2002 lol... IMO, scanf() is a fine reason to use COBOL
- Carlos (13/18) May 06 2002 Like this?
- Pavel Minayev (14/15) May 06 2002 Like this:
- Carlos (2/14) May 06 2002 So, basically, every single time you want to read a string, you must cre...
- Pavel Minayev (6/8) May 06 2002 create
Hi. I'm 100% new in D, but I know C/C++. I've been reviewing the help and the forum, and there's something that I still can't find: how can I read strings (or an array of chars) from the keyboard. I know it sounds silly, but believe me, I can't. Also, this code doesn't work: import c.stdio; void main() { float f; scanf("%f",&f); printf("You entered: %f\n",f); } It shows "You entered: 0.0000", doesn't matter what you enter. It works if f is int or char, but not if float. Why? Is it that there're some easter-eggs in D? Thanks
May 01 2002
"Carlos" <Carlos_member pathlink.com> wrote in message news:aapkrj$24b0$1 digitaldaemon.com...Hi. I'm 100% new in D, but I know C/C++. I've been reviewing the help andtheforum, and there's something that I still can't find: how can I readstrings (oran array of chars) from the keyboard.At the moment, use the corresponding C functions.I know it sounds silly, but believe me, I can't. Also, this code doesn't work: import c.stdio; void main() { float f; scanf("%f",&f); printf("You entered: %f\n",f); } It shows "You entered: 0.0000", doesn't matter what you enter. It works iff isint or char, but not if float. Why? Is it that there're some easter-eggsin D? What's happening is that, unlike C, the f is passed to printf() as a float. It is interpreted by printf, however, as a double. You can fix it with: printf("You entered: %f\n", (double)f);
May 01 2002
How am I supposed to do the string reading? I've tried everything. This should be the way, but doesn't work: import c.stdio; void main() { char[] str; scanf("%s",str); //or should I use gets()? or &str? printf("You wrote: %.*s\n",str); } --------- In article <aapnca$2958$1 digitaldaemon.com>, Walter says..."Carlos" <Carlos_member pathlink.com> wrote in message news:aapkrj$24b0$1 digitaldaemon.com...Hi. I'm 100% new in D, but I know C/C++. I've been reviewing the help andtheforum, and there's something that I still can't find: how can I readstrings (oran array of chars) from the keyboard.At the moment, use the corresponding C functions.I know it sounds silly, but believe me, I can't. Also, this code doesn't work: import c.stdio; void main() { float f; scanf("%f",&f); printf("You entered: %f\n",f); } It shows "You entered: 0.0000", doesn't matter what you enter. It works iff isint or char, but not if float. Why? Is it that there're some easter-eggsin D? What's happening is that, unlike C, the f is passed to printf() as a float. It is interpreted by printf, however, as a double. You can fix it with: printf("You entered: %f\n", (double)f);
May 01 2002
"Carlos" <Carlos_member pathlink.com> wrote in message news:aaq2ep$15l$1 digitaldaemon.com...How am I supposed to do the string reading? I've tried everything. Thisshouldbe the way, but doesn't work: import c.stdio; void main() { char[] str; scanf("%s",str); //or should I use gets()? or &str? printf("You wrote: %.*s\n",str); }The key is C doesn't do dynamic arrays, it does pointers. So: char[] str; char *s; scanf("%s", &s); str = s[0 .. c.strlen(s)];
May 01 2002
Walter wrote:"Carlos" <Carlos_member pathlink.com> wrote in message news:aaq2ep$15l$1 digitaldaemon.com...Ack, that 'taint right, is it? s is uninitialized there, and the scanf is getting a pointer to pointer! (Although, I have a whole closet full of ten foot poles with which I wouldn't touch scanf() in the first place...) -RHow am I supposed to do the string reading? I've tried everything. Thisshouldbe the way, but doesn't work: import c.stdio; void main() { char[] str; scanf("%s",str); //or should I use gets()? or &str? printf("You wrote: %.*s\n",str); }The key is C doesn't do dynamic arrays, it does pointers. So: char[] str; char *s; scanf("%s", &s); str = s[0 .. c.strlen(s)];
May 02 2002
"Russell Borogove" <kaleja estarcion.com> wrote in message news:3CD21E39.7020500 estarcion.com...scanf initializes the pointer.char[] str; char *s; scanf("%s", &s); str = s[0 .. c.strlen(s)];Ack, that 'taint right, is it? s is uninitialized there, and the scanf is getting a pointer to pointer!(Although, I have a whole closet full of ten foot poles with which I wouldn't touch scanf() in the first place...)I usually find myself writing a real lexer when I need one <g>.
May 03 2002
Walter wrote:"Russell Borogove" <kaleja estarcion.com> wrote in message news:3CD21E39.7020500 estarcion.com...Not in standard C: (Unless that's a D scanf and I'm missing something?) I think you want: char s[ DO_YOU_FEEL_LUCKY_LENGTH ]; scanf( "%s", s ); -Rscanf initializes the pointer.char[] str; char *s; scanf("%s", &s); str = s[0 .. c.strlen(s)];Ack, that 'taint right, is it? s is uninitialized there, and the scanf is getting a pointer to pointer!
May 03 2002
Oops! You're right. Yet another reason to use D! "Russell Borogove" <kaleja estarcion.com> wrote in message news:3CD2BE38.4000802 estarcion.com...Walter wrote:"Russell Borogove" <kaleja estarcion.com> wrote in message news:3CD21E39.7020500 estarcion.com...Not in standard C: (Unless that's a D scanf and I'm missing something?) I think you want: char s[ DO_YOU_FEEL_LUCKY_LENGTH ]; scanf( "%s", s ); -Rscanf initializes the pointer.char[] str; char *s; scanf("%s", &s); str = s[0 .. c.strlen(s)];Ack, that 'taint right, is it? s is uninitialized there, and the scanf is getting a pointer to pointer!
May 03 2002
Walter wrote:Oops! You're right. Yet another reason to use D!lol... IMO, scanf() is a fine reason to use COBOL or BASIC! -R
May 04 2002
The key is C doesn't do dynamic arrays, it does pointers. So: char[] str; char *s; scanf("%s", &s); str = s[0 .. c.strlen(s)];Like this? import c.stdio; import string; void main() { char[] w; char *w1; printf("Write your name: "); scanf("%s",&w); w=w1[0..strlen(w1)]; printf("Hi, %.*s\n",w); } Doesn't work!
May 06 2002
"Carlos" <carlos8294 msn.com> wrote in message news:ab7in0$k5l$1 digitaldaemon.com...Like this?Like this: import c.stdio; import string; int main() { char[] w; char[100] w1; printf("Write your name: "); scanf("%s", w1); w = w1[0 .. strlen(w1)]; printf("Hi, %.*s\n", w); }
May 06 2002
Like this: import c.stdio; import string; int main() { char[] w; char[100] w1; printf("Write your name: "); scanf("%s", w1); w = w1[0 .. strlen(w1)]; printf("Hi, %.*s\n", w); }So, basically, every single time you want to read a string, you must create two spaces in memory. Isn't this redudant, absurd or something like that?
May 06 2002
"Carlos" <carlos8294 msn.com> wrote in message news:ab7j5i$kj8$1 digitaldaemon.com...So, basically, every single time you want to read a string, you mustcreatetwo spaces in memory. Isn't this redudant, absurd or something like that?It is. It's because the D run-time library, Phobos, is far from completion, so you have to use C functions. Of course, later versions will introduce a better way to read user input.
May 06 2002