Help variable reads t 
Author Message
 Help variable reads t


 In> Program a6q3;
 In> uses wincrt;

 In> type
 In>    book= record
 In>    author: array[1..15] of char;
 In>    title: array[1..30] of char;
 In>    year:integer;
 In>    price: real;
 In> end; {book}
 In> Type
 In>    libr = array[1..20] of book;
 In> Var
 In>    T:libr;
 In>    l,p,count:integer;
 In>    stop:char;

 In> Procedure readauthor(i,counter:integer);
 In> Begin
 In>    write('Please enter author:  ');
 In>    while not eoln do
 In>    begin
 In>       I:=I+1;
 In>       read(t[counter].author[I]);
 In>       write(t[counter].author[I]);
 In>    end;
 In>    readln;
 In> end;

 In> Procedure ReadTitle(i,counter:integer);
 In> Begin
 In>    write('Please enter title:  ');
 In>    while not eoln do
 In>    begin
 In>       read(t[counter].title[i]);
 In>       i:=i+1;
 In>    end;
 In>    readln;
 In> end;

 In> Begin
 In>    stop:='y';
 In>    While stop='y' do
 In>    begin
 In>       count:=count+1;
 In>       ReadAuthor(l,count);
 In>       ReadTitle(p,count);
 In>       PrintAuthor(l,count);
 In>       {Printtitle(p,count); }
 In>    end;
 In> end.

 In> THis is my program now when I run it can anyone tell me why I would
 In> get the t[counter].author variable to contain also the first letter of
 In> the title.  Help would be greatly appreciated.

In your main block you call ReadAuthor and pass it the variables l and count,
yet neither of these have a known value since they were never initialized at
the start of the program. Place statements at the start of the main block to
initialize all global counters to 0 and that should fix that problem.

You might also do away with the cumbersome "while not Eoln do" and the
Read() statements to get input, and replace them with simpler ReadLn()
statements. ReadLn() will take input until <enter> is pressed. Also, switch
your arrays of char to strings and I bet you could reduce the entire program
to less than half it's size, removing the need for all loops except the main
one.

  /-=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=-\

  %        Author of Disk Ease v0.9.2 Floppy Disk Indexer/Database       $
  $               http://www.*-*-*.com/ ~kforwood/              %
  \-=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=-/
            WARNING:  Unsolicited advertising will be reported
                  to your ISP. Flames merely laughed at.

___ Blue Wave/QWK v2.20



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Help variable reads too far THANX to anyone who tries to help

2. Reading different size variables from same open file in Turbo Pascal 3.0

3. Pascal refuses to read a string variable...

4. Read-only variables

5. How can I read text files into variables?

6. Read variables from text file?

7. Reading REAL variable

8. How to read MSDOS variables from TP 4.0

9. Was - Reading REAL Variable

10. Reading REAL Variable

11. Save/read variable values in a file

12. DELPHI: Anyway to read Dos environmental variables?

 

 
Powered by phpBB® Forum Software