From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,56e5e06428166864 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!b8g2000vbi.googlegroups.com!not-for-mail From: Stoik Newsgroups: comp.lang.ada Subject: Re: problems with interfacing c Date: Thu, 27 Jan 2011 16:39:50 -0800 (PST) Organization: http://groups.google.com Message-ID: <85c958cc-8cd3-46be-b14d-3519ff207d87@b8g2000vbi.googlegroups.com> References: <8b6a5b24-5ab0-4d38-9be8-86911aba7fcf@k22g2000yqh.googlegroups.com> <13d5wy5ni51xh$.xnhoi3uhm9ql.dlg@40tude.net> NNTP-Posting-Host: 212.191.65.1 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1296175190 7148 127.0.0.1 (28 Jan 2011 00:39:50 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 28 Jan 2011 00:39:50 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: b8g2000vbi.googlegroups.com; posting-host=212.191.65.1; posting-account=fc1UmgoAAADREbhuD8e4smj7nsEdRFz9 User-Agent: G2/1.0 X-HTTP-Via: 1.1 proxy.math.uni.lodz.pl:8080 (squid/2.7.STABLE4) X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.237 Safari/534.10,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:17728 Date: 2011-01-27T16:39:50-08:00 List-Id: On Jan 20, 9:56=A0pm, "Dmitry A. Kazakov" 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 =3D (char*)malloc(100000); > > fread(bufor, 1, 100000, stdin); > > That depends on what are going to achieve. Translating the above literall= y: > > [ with Ada.Text_IO.Text_Streams; > =A0 use Ada.Text_IO, Ada.Text_IO.Text_Streams; ] > > =A0 =A0Buffer : String (1..100_000); > begin > =A0 =A0String'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, u= se 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