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.3 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT,SUBJ_ALL_CAPS autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b1f7daf91f8dae42,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-11-09 06:18:17 PST Path: nntp.gmd.de!xlink.net!howland.reston.ans.net!EU.net!uunet!dprmpt!dpss From: dpss@dprmpt.dataprompt.com (Shujaat Siddiqui) Newsgroups: comp.lang.ada Subject: READ A STRING FROM A FILE Message-ID: <907@dprmpt.dataprompt.com> Date: 8 Nov 94 14:40:13 GMT Organization: Data-Prompt, Inc., Silver Spring, MD Date: 1994-11-08T14:40:13+00:00 List-Id: I am helping someone in writing this ADA program for his class. I tried to read from the book to how to read a STRING from a text file, but I could not find anythng, that is the only place I am stuck. The Data file is something like this. Danny 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 Danny 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 Danny 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 Danny 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 Danny 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 The programm goes like this. Only place I am stuck is how to read in the STRING from above given DATA file. with Text_IO; procedure Test_Average is -- This program finds the weighted average of three test scores -- Packages for numeric input and output -- package characters is new Text_IO.words (Name => Characters); package Integer_IO is new Text_IO.Integer_IO (Num => Integer); package Float_IO is new Text_IO.Float_IO (Num => Float); -- Variables Scores : Text_IO.File_Type; -- Input data file -- Scores for the three tests -- Name1 : String(1..12); -- Last_Char : Integer; Check : Integer; Fl1 : Integer; Fl2 : Integer; Fl3 : Integer; Home : Integer; Project : Integer; Exam : Integer; Tot_HW : Integer; Tot_Pj : Integer; Tot_EX : Integer; Counter: Integer; -- Weights for the three tests Ave_HW : Float; Ave_PJ : Float; Ave_EX : Float; Class_HW : Float; -- Weighted average of the tests Class_PJ : Float; Class_EX : Float; begin -- Prepare file for reading Fl1 := 1; Fl2 := 1; Fl3 := 1; Tot_HW := 0; Tot_PJ := 0; Tot_EX := 0; Ave_HW := 0.0; Ave_PJ := 0.0; Ave_EX := 0.0; Class_EX := 0.0; Class_PJ := 0.0; Class_HW := 0.0; Counter := 0; Text_IO.Open (File => Scores, Mode => Text_IO.IN_FILE, Name => "SCORES.DAT"); -- Get Data -- Text_IO.Put (Item => "Eneter: "); -- Text_IO.Get_Line (Item => Name1, Last => Last_Char); Counter := Counter + 1; HomeWork_Loop: while Fl1 /= 8 loop Integer_IO.Get (File => Scores, Item => Home); Tot_HW := Tot_HW + Home; end loop HomeWork_Loop; Ave_HW := Float (Tot_HW / 8.0); Proj_Loop: while Fl2 /= 4 loop Integer_IO.Get (File => Scores, Item => Project); Tot_PJ := Tot_PJ + Project; end loop Proj_Loop; Ave_PJ := Float (Tot_PJ / 4.0); Exam_Loop: while Fl3 /= 3 loop Integer_IO.Get (File => Scores, Item => Exam); Tot_EX := Tot_EX + Exam; end loop Exam_loop; Ave_EX := Float (Tot_EX / 3.0); Class_EX := Class_Ex + Ave_EX; Class_HW := Class_HW + Ave_HW; Class_PJ := Class_PJ + Ave_PJ; Float_IO.Get (File => Scores, Item => Weight3); -- Print heading -- Text_IO.Put (Item => "Test Score Weight"); Text_IO.New_Line; Text_IO.New_Line; -- Print data -- Text_IO.Put (Item => Name1 ); Text_IO.New_Line; Text_IO.Put (Item => "Homework average = "); Float_IO.Put (Item => Class_HW, Fore => 3, Aft => 2, Exp => 0); Text_IO.Put (Item => "Exams average = "); Float_IO.Put (Item => Class_EX, Fore => 3, Aft => 2, Exp => 0); Text_IO.Put (Item => "Projects average = "); Float_IO.Put (Item => Class_PJ, Fore => 3, Aft => 2, Exp => 0); Text_IO.Close (File => Scores); -- Sever connection to disk file Text_IO.New_Line; Text_IO.New_Line; -- Find weighted average Class_EX := Class_EX / Counter; Class_PJ := Class_PJ / Counter; Class_HW := Class_HW / Counter; Text_IO.Put (Item => "Class Homework average = "); Float_IO.Put (Item => Class_HW, Fore => 3, Aft => 2, Exp => 0); Text_IO.Put (Item => "Class Project average = "); Float_IO.Put (Item => Class_PJ, Fore => 3, Aft => 2, Exp => 0); Text_IO.Put (Item => "Class Exams average = "); Float_IO.Put (Item => Class_EX, Fore => 3, Aft => 2, Exp => 0); Text_IO.New_Line; end Test_Average; I will really appreciate it. Thanks in ADVANCE!!!!!!!!!!!!!!!!!!!!!!!!!! ** ************************************************************************** * _|_ * * Shujaat H. Siddiqui Phone: (301)622-0900 Ext: 305 | -----(_)----- * * ELM Adress: dpss@dprmpt.dataprompt.com | ! ! ! * **************************************************************************