D - help with: scanf("%.*s", a[])
- Andrew Edwards (61/61) May 31 2003 Hello everyone!
-
Carlos Santander B.
(14/14)
May 31 2003
"Andrew Edwards"
escribiσ en el mensaje - Andrew Edwards (10/16) May 31 2003 Thanks!
Hello everyone!
I'd first like to say that I'm quite impressed at the
work that has gone on since I disappeared in February.
Kudos on a job well done! I'd also like to thank and
apologize to everyone that responded to my request
for aid on my "Unicode: Japanese Study Program".
I have not had the time, until now to even look at your
responses. To everyone that has emailed me about
working on a D Tutorial, I'm sorry that I couldn't get
back to you.
My Excuse: The Marines called and I had to run.
Just returned on Friday! (Probably lame...but true!)
Now! The nature of my problem.
I'm trying to accomplish the following:
import stream;
int main()
{
char[] a = "Hello! Welcome to D!";
printf("%.*s\n", a);
printf("What did you say your name was again? ");
scanf("%.*s", a); // &a doesn't work either
printf("Well %.*s, I wish you the best of luck!", a);
return 0;
}
D output:
Hello! Welcome to D!
What did you say your name was again? Andrew
Well Hello! Welcome to D!, I wish you the best of luck!
-------------------------------------------------------------
Review of stream.d reveals the following definition
for scanf().
int scanf(char[] format, ...)
{
va_list ap;
ap = cast(va_list) &format;
ap += format.size;
return vscanf(format, ap);
}
This how vscanf() handles 'D' strings
// D string?
bit dstr = false;
if (fmt[i] == ".")
{
i++;
if (fmt[i] == "*")
{
dstr = true;
i++;
}
}
if (dstr) // D string (char[])
*cast(char[]*)*arg = s;
else // C string (char*)
{
s ~= 0;
(cast(char*)*arg)[0 .. s.length] = s[];
}
-------------------------------------------------------------
I'm not sure if it's something I'm doing wrong or
something wrong with the scanf()/vscanf() implementation.
Please advise.
May 31 2003
"Andrew Edwards" <edwardsac spamfreeusa.com> escribiσ en el mensaje
news:bbbh1p$2ut5$1 digitaldaemon.com...
| Hello everyone!
Hi, welcome back.
| scanf("%.*s", a); // &a doesn't work either
I think this should be stream.scanf, but it doesn't work either. Why don't
you read a 0-terminated string and copy it to "a"? Or maybe you could use
gets instead of scanf.
Carlos Santander
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.486 / Virus Database: 284 - Release Date: 2003-05-29
May 31 2003
"Carlos Santander B." <carlos8294 msn.com> wrote in message news:bbblun$22g$1 digitaldaemon.com..."Andrew Edwards" <edwardsac spamfreeusa.com> escribiσ en el mensaje news:bbbh1p$2ut5$1 digitaldaemon.com...Hi, welcome back.Thanks!I think this should be stream.scanf, but it doesn't work either. Why don't you read a 0-terminated string and copy it to "a"? Or maybe you could use gets instead of scanf.After I import stream, I didn't think I have to clarify which scanf I'm trying to use. As for the 0-terminated strings and gets, I'm not interested in using C functions, because I don't know C. Stream.d seams to address the use of scanf for D strings, so I'd like to learn it the D way.
May 31 2003








"Andrew Edwards" <edwardsac spamfreeusa.com>