From: kst@thomsoft.com (Keith Thompson)
Subject: Re: newbie binary file I/O question
Date: Sun, 5 Mar 1995 23:04:14 GMT
Date: 1995-03-05T23:04:14+00:00 [thread overview]
Message-ID: <D4zpF3.64M@thomsoft.com> (raw)
In-Reply-To: D4vHw0.LB@nvl.army.mil
In <D4vHw0.LB@nvl.army.mil> shaffer@oliver (Dolores Shaffer) writes:
> I am using an old Telesoft Ada compiler on a Sun workstation. I have
> a binary file that I would like to open and read one byte at a time.
> If the code asks the user for the file name and then stores that in
> a string variable, and the code passes that variable to the open
> procedure, I get a NAME_ERROR and the code bombs. If the code
> passes the name of the binary file in quotes, it works. I am
> able to use text_io.open to open text files whose names are passed to
> open in a string variable. Any suggestions?
[...]
> name_of_file: string(1..80);
> name_length : natural;
>
> begin
> text_io.put_line("enter name of file to open");
> text_io.get_line(name_of_file,name_length);
>
> byte_io.open(din_file, byte_io.file_mode'first, name=>name_of_file);
> --IT BOMBS HERE!!
> --but byte_io.open(din_file, byte_io.file_mode'first, "filename"); works
The contents of the variable Name_Of_File past Name_Length are undefined.
The name the user entered is in the slice
Name_Of_File(1 .. Name_Length)
Use that instead of just Name_Of_File in the Open call.
Someone else suggested initializing Name_Of_File to all blanks; this is
unlikely to work. Under Unix, for example, a blank is a valid character
in a file name; "foo" and "foo " are legal and distinct file names.
Digression:
To be more precise about what's going on, change the variable Name_Length
to Name_Last, and use the slice
Name_Of_File(Name_Of_File'First .. Name_Last)
Not all strings are one-based; for strings that aren't one-based,
the 'Last is not the same as the 'Length. In this particular case,
you know Name_Of_File is one-based because you declared it that way,
but it's still better to be explicit.
end Digression;
--
Keith Thompson (The_Other_Keith) kst@thomsoft.com (kst@alsys.com still works)
TeleSoft^H^H^H^H^H^H^H^H Alsys^H^H^H^H^H Thomson Software Products
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2718
That's Keith Thompson *with* a 'p', Thomson Software Products *without* a 'p'.
next prev parent reply other threads:[~1995-03-05 23:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1995-03-03 16:31 newbie binary file I/O question Dolores Shaffer
1995-03-04 16:01 ` Tore Joergensen
1995-03-05 23:04 ` Keith Thompson [this message]
1995-03-14 16:18 ` Michael M. Bishop
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox