comp.lang.ada
 help / color / mirror / Atom feed
From: Stoik <staszek.goldstein@gmail.com>
Subject: Re: problems with interfacing c
Date: Thu, 27 Jan 2011 16:39:50 -0800 (PST)
Date: 2011-01-27T16:39:50-08:00	[thread overview]
Message-ID: <85c958cc-8cd3-46be-b14d-3519ff207d87@b8g2000vbi.googlegroups.com> (raw)
In-Reply-To: 13d5wy5ni51xh$.xnhoi3uhm9ql.dlg@40tude.net

On Jan 20, 9:56 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> On Thu, 20 Jan 2011 12:21:08 -0800 (PST), Stoik wrote:
> > I need your help in finding a proper Ada code to simulate the behaviour of the
> > following lines in C:
> > char *bufor = (char*)malloc(100000);
> > fread(bufor, 1, 100000, stdin);
>
> That depends on what are going to achieve. Translating the above literally:
>
> [ with Ada.Text_IO.Text_Streams;
>   use Ada.Text_IO, Ada.Text_IO.Text_Streams; ]
>
>    Buffer : String (1..100_000);
> begin
>    String'Read (Stream (Standard_Input), Buffer);
>
> [ Which certainly nobody would do, but you didn't provide any information
> about the actual problem. ]
>
> > I need to do it from inside of the Ada code. I tried to import fread, use the package
> > interfaces.c.strings etc, but in the end I always get the same message:
> > raised PROGRAM_ERROR : EXCEPTION_ACCESS_VIOLATION
> > Any ideas?
>
> You are using C bindings improperly and you need not C bindings in order to
> read the standard input.
>
> --
> Regards,
> Dmitry A. Kazakovhttp://www.dmitry-kazakov.de

Thanks for your suggestions and comments. The point is that I am
sending
a solution to a problem to a site managing programming contests, and
the stdin
is in fact redirected to some text file with data. I do not know how
big the data file
will be, I know only the upper limit. Quick reading of the data is the
key to success,
and the two lines of C work very well for the purpose. I have not
tried your solution,
is it not going to cause constraint_error when it meets the end of the
file?
The other question is - how to use the C bindings properly in such a
case?

Regards,
Staszek Goldstein



  parent reply	other threads:[~2011-01-28  0:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-20 20:21 problems with interfacing c Stoik
2011-01-20 20:56 ` Dmitry A. Kazakov
2011-01-20 21:31   ` Yannick Duchêne (Hibou57)
2011-01-20 23:03     ` Dmitry A. Kazakov
2011-01-21  0:46       ` Yannick Duchêne (Hibou57)
2011-01-21  9:33         ` Dmitry A. Kazakov
2011-01-28  0:39   ` Stoik [this message]
2011-01-28  5:24     ` Yannick Duchêne (Hibou57)
2011-01-28  9:41     ` Ludovic Brenta
2011-01-28  9:44     ` Dmitry A. Kazakov
2011-01-31 21:46       ` Stoik
2011-01-31 23:06         ` Edward Fish
2011-02-01  8:48         ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox