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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,2e1e48cc9f87abf9 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-03-06 19:07:26 PST Newsgroups: comp.lang.ada Path: bga.com!news.sprintlink.net!cs.utexas.edu!uunet!telesoft!kst From: kst@thomsoft.com (Keith Thompson) Subject: Re: newbie binary file I/O question Message-ID: Originator: kst@pulsar Keywords: sequential_io Sender: news@thomsoft.com (USENET News Admin @flash) Organization: Thomson Software Products, San Diego, CA, USA References: Date: Sun, 5 Mar 1995 23:04:14 GMT Date: 1995-03-05T23:04:14+00:00 List-Id: In 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'.