Thread overview
Errors in simple program.
Mar 20, 2003
madamephreaker
Mar 20, 2003
Burton Radons
Mar 21, 2003
madamephreaker
Mar 21, 2003
madamephreaker
Mar 21, 2003
Walter
March 20, 2003
When I use printf in the way i'm doing now(see code) it crashes flat out. If i just do "printf(input);" it works until it gets to a blank line.

In all cases it gives "Error: Access Violation" when it crashes.

--- Begin hello.d
import c.stdio;
import stream;

int main( char[][] args )
{
char[] input="";
File myFile = new File(args[1]);
while( ! myFile.eof() )
{
input = myFile.readLine();
printf("%s\n", input);
}
myFile.close();
return 0;
}
--- End hello.d


March 20, 2003
madamephreaker@hotmail.com wrote:
> printf("%s\n", input);

Use "%.*s\n".

March 21, 2003
In article <b5dglk$28cu$1@digitaldaemon.com>, Burton Radons says...
>
>madamephreaker@hotmail.com wrote:
>> printf("%s\n", input);
>
>Use
"%.*s\n".
>

What about the multiple lines? and when i use printf(input);
?
input isn't always declared? I'm assuming since result in the stream class is
a resizable array when it doesn't get anything it it it's a pointer to an array
of length zero? Thus accessing it blows up?  Why would "%.*s" fix that?


March 21, 2003
In article <b5dm68$2c4e$1@digitaldaemon.com>, madamephreaker@hotmail.com says...
>
>In article <b5dglk$28cu$1@digitaldaemon.com>, Burton
Radons
>says...
>>
>>madamephreaker@hotmail.com wrote:
>>> printf("%s\n",
input);
>>
>>Use
>"%.*s\n".
>>

I just switched to using that now, and it works.
to some extent.. If the last line of the file doesn't end in a newline it spews
this out:

not enough data in stream

Although looking at it more i think dli
0.1.2 just has an old version of phobos. (I tried updating but it failed to
compile parts of phobos then)



March 21, 2003
<madamephreaker@hotmail.com> wrote in message news:b5dm68$2c4e$1@digitaldaemon.com...
>Why would "%.*s" fix that?

The input[] is a dynamic array, which consists of a length field and a pointer to the data. %s expects a pointer to a null terminated string. %.*s expects two parameters, a length and a pointer, which fits perfectly with D arrays.