From: Martin Krischik <krischik@users.sourceforge.net>
Subject: Re: Using fwrite in Ada
Date: Wed, 10 Aug 2005 20:05:55 +0200
Date: 2005-08-10T20:05:55+02:00 [thread overview]
Message-ID: <2629229.pEnVhKcNl9@linux1.krischik.com> (raw)
In-Reply-To: dddbut$7qm$1@newsm1.svr.pol.co.uk
Makhno wrote:
> Hello,
> I want to read and write binary data from stdin/stdout, unfortunately
> Ada's usual IO routines appear to be text only and (on Win32) convert code
> 10 to codes 10 & 13.
Not at all true:
http://en.wikibooks.org/wiki/Programming:Ada:InputOutput
Sadly the articles which describe how to attach any stream type to
stdin/stdout has not been written yet :-( .
> To get round this I'm trying to use Interfaces.C_Streams, but I don't know
> enough Ada to get them working.
> How to I get a String into the fwrite function?
> I tried
>
> procedure MainCode is
>
> cptr : chars_ptr;
> Buffer : String (1..100);
Are you sure you use the right String type?
http://en.wikibooks.org/wiki/Programming:Ada:Strings
> vptr : voids;
>
> begin
>
> -- fill Buffer with binary data here
>
> cptr:=New_String(Buffer);
> vptr:=voids(cptr);
>
> fwrite(vptr,100,1,stdout);
> end;
>
> But this won't compile, the compiler says that it cannot convert the
> chars_ptr to voids. Coming from a C background, I don't understand why
> something cannot be cast to void.
Read:
http://en.wikibooks.org/wiki/Programming:Ada:Subtypes#Converting_data
and
http://en.wikibooks.org/wiki/Programming:Ada:Types:access
> Does anybody have any idea as to how I get binary data onto stdout?
If it is truly binary data of a fixed length of 100 bytes I would suggest
Direct I/O:
http://en.wikibooks.org/wiki/Programming:Ada:InputOutput#Direct_I.2FO
But you should really read the suggested web pages.
Martin
--
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com
next prev parent reply other threads:[~2005-08-10 18:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-10 17:01 Using fwrite in Ada Makhno
2005-08-10 17:28 ` Georg Bauhaus
2005-08-10 18:05 ` Martin Krischik [this message]
2005-08-11 17:01 ` tmoran
2005-08-11 21:59 ` Jeffrey Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox