|
Archives
D Programming
digitalmars.Ddigitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger D.gnu D C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
D - scanf("%.*s",str) revisited
Every now and then this topic rears it's ugly head but there seem to be
no real solution for to the problem. I'm trying to scan a string
(char[]) from a text document or from stdin. What is the correct way to
do this? I am aware of the readLine and readString functions available
in stream.d but this is not exactly what I'm looking for. Additionally I
could:
char[] str;
char[80] s;
scanf("%s",cast(char*)s);
str = toStringz(s);
but this does not alleviate the problem. Since dynamic string (char[])
guards against array overrunning, it is my first choice when considering
string input. I think this is a problem that needs to be remedied,
especially for novice programmers (not to say that we are the only ones
that use such features), prior to v1.0?
Feb 15 2004
"Andrew Edwards" <remove_ridimz remove_yahoo.com> wrote in message
news:c0ol66$28jl$1 digitaldaemon.com...
| Every now and then this topic rears it's ugly head but there seem to be
| no real solution for to the problem. I'm trying to scan a string
| (char[]) from a text document or from stdin. What is the correct way to
| do this? I am aware of the readLine and readString functions available
| in stream.d but this is not exactly what I'm looking for. Additionally I
| could:
|
| char[] str;
| char[80] s;
| scanf("%s",cast(char*)s);
|
| str = toStringz(s);
|
| but this does not alleviate the problem. Since dynamic string (char[])
| guards against array overrunning, it is my first choice when considering
| string input. I think this is a problem that needs to be remedied,
| especially for novice programmers (not to say that we are the only ones
| that use such features), prior to v1.0?
Did you try the scanf method in std.stream instead of the std.c.scanf?
stdin.scanf("%.s",&str);
Feb 15 2004
Ben Hinkle wrote: Feb 15 2004
Feb 16 2004
Sam McCall wrote: Feb 16 2004
"Sam McCall" <tunah.d tunah.net> wrote in message
news:c0q2mq$1g60$1 digitaldaemon.com...
| > char[] str;
| > stdin.scanf("%.s",&str);
| > printf(str);
| >
| > results in:
| >
| > C:\>test
| > Error: Access Violation
| Should that be %.*s or %s?
oops. that should be %.*s
| I don't know, just wondering...
| Sam
Feb 16 2004
Ben Hinkle wrote: Feb 15 2004
|