comp.lang.ada
 help / color / mirror / Atom feed
* Beginners Ada Question on Ada IO.
@ 1996-12-11  0:00 Konstantin Gromov
  1996-12-11  0:00 ` Stephen Leake
  0 siblings, 1 reply; 4+ messages in thread
From: Konstantin Gromov @ 1996-12-11  0:00 UTC (permalink / raw)
  Cc: gkg


Hello everyone,

	I just started learning Ada, and I like it better than C or C++.
But one thing drive me nuts... All text books and tutorials talk 
only about character IO, and in what I am doing I need binary IO.
I am trying to generate some data and then output it to the file byte
by byte. (Later I'll have to read binary data from one file (really
device)
and send it to another.) All this happens under Unix. 

	Here example of what I am trying to do:

  ....
type EEPROM is array(0 .. 16383 , 0 .. 6) of Integer range 0 .. 255;
  ....
Data              : EEPROM;
ROM_File          : Ada.Text_IO.File_Type;
  ....
  -- Here I am stuffing array "Data" with some numbers
  .... 
Ada.Text_IO.Create(ROM_File, Ada.Text_IO.Out_File, "rom.dat");
for A in 0 .. 16383
loop
   -- Next line is a line wich causes me problems.
   -- Basicly I am trying to do C thing: "putc(Data(A,6), ROM_File);"
   -- but it is wrong, and I cannot find an answer...
   Ada.Text_IO.Put ( Item => (Character)Data(A,6), File => ROM_File );  
   Ada.Text_IO.New_Line(File => ROM_File);
end loop;
Ada.Text_IO.Close(ROM_File);


I'll appreciate any help or hints on where I can find a detailed 
information on the subject.

Please answer via email.

Thank you in advance for your help.

Konstantin Gromov
gkg@leland.stanford.edu




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Beginners Ada Question on Ada IO.
  1996-12-11  0:00 Beginners Ada Question on Ada IO Konstantin Gromov
@ 1996-12-11  0:00 ` Stephen Leake
  1996-12-11  0:00   ` Larry Kilgallen
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Leake @ 1996-12-11  0:00 UTC (permalink / raw)



Konstantin Gromov wrote:
> But one thing drive me nuts... All text books and tutorials talk
> only about character IO, and in what I am doing I need binary IO.
> I am trying to generate some data and then output it to the file byte
> by byte.
> [example code deleted]
> 
> I'll appreciate any help or hints on where I can find a detailed
> information on the subject.

You need to instantiate either Sequential_IO or Direct_IO.

> 
> Please answer via email.

Sorry, News is a two-way participatory forum; if you want answers, you
have to read questions (and hopefully answer some!).

> 
> Thank you in advance for your help.
> 

You're welcome.

> Konstantin Gromov
> gkg@leland.stanford.edu

-- 
- Stephe




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Beginners Ada Question on Ada IO.
  1996-12-11  0:00 ` Stephen Leake
@ 1996-12-11  0:00   ` Larry Kilgallen
  0 siblings, 0 replies; 4+ messages in thread
From: Larry Kilgallen @ 1996-12-11  0:00 UTC (permalink / raw)



In article <32AEC7F7.15C4@gsfc.nasa.gov>, Stephen Leake <Stephen.Leake@gsfc.nasa.gov> writes:
> Konstantin Gromov wrote:

<helpful answer from Stephen Leake snipped>

>> Please answer via email.
> 
> Sorry, News is a two-way participatory forum; if you want answers, you
> have to read questions (and hopefully answer some!).

And of course hopefully read some previous answers to avoid duplicate
questions !

Larry Kilgallen




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Beginners Ada Question on Ada IO.
@ 1996-12-12  0:00 tmoran
  0 siblings, 0 replies; 4+ messages in thread
From: tmoran @ 1996-12-12  0:00 UTC (permalink / raw)



Look up Sequential_IO in your textbook.  Sequential_IO is a generic
which you instantiate with an IO record type - in your case a record
consisting of a single byte.
  BTW, I note you have an integer with range 0 .. 255.  The compiler
will not necessarily store that as 8 bits, and the record you write
won't necessarily be only 8 bits, unless you define a type and
use a 'size clause to force it to 8 bits.
  Also, your C-Ada code does a new_line; do you really want to put
CRs/LFs in your binary file?  If you use Sequential_IO you will have
to do that explicitly by writing a byte (or two) with the right
values, rather than letting the system mark end-of-line according
to its own conventions.




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1996-12-12  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-12-11  0:00 Beginners Ada Question on Ada IO Konstantin Gromov
1996-12-11  0:00 ` Stephen Leake
1996-12-11  0:00   ` Larry Kilgallen
  -- strict thread matches above, loose matches on Subject: below --
1996-12-12  0:00 tmoran

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