Solved

Reading External Text Files

Posted on 1998-11-22
8
170 Views
Last Modified: 2012-05-04
How do I read in a list of names from an external text file? I would like to read in two lists of alphabetized names from separate text files and merge them into one alphabetical list.  I would also like to print out any name from either of the two external lists, say the 5th name of list2.  Any help in this matter would be greatly appreciated.  
0
Comment
Question by:willie117
  • 5
  • 2
8 Comments
 

Author Comment

by:willie117
ID: 1216168
e-mail is jayleff@aol.com
0
 
LVL 1

Expert Comment

by:FuzzyLogic
ID: 1216169
To merge two ordered lists into one list is easy, and I can give you basic code for that.

However, when you said "print out any name...", do you mean that:
A. The program waits for user query and writes out the answer  (and wait for another query)?
B. The user give his query at command-line and the program processes his query?

Fuzzy
0
 

Author Comment

by:willie117
ID: 1216170
Once the list is compiled, the user then can query, say for the 4th name in the list.
0
 
LVL 27

Expert Comment

by:BigRat
ID: 1216171
It really depends how big the files are and how long the names are. If the files are relatively small and the names less than say 60 characters you can hold all of it in memory. For example assume the names are on one line in the file :-
       Homer Simpson
       Heffer Wolf
       Barney Rubble
    and so on, up to say several hundred, the creating a list like :-

     PNameList = ^TNameList;
     TNameList = record
                 Next : PNameList;
                 Name : PChar;
                 end;
   while not(EOF(Input)) do
      begin
      Readln(Input,Name);
      new(Entry);
      Entry^.Next:=List;
      List^.Name:=StrNew(Name);
      List:=Entry;
      end;
in memory gives you a simple list. All the names are stored on the heap. If this is waht you are thing about reply and we'll lok further!. If not ignore it!
     have ratitude
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:willie117
ID: 1216172
That looks good, the files are small and the names are less than 60.  Also is it possible to use an array with this?
0
 
LVL 27

Accepted Solution

by:
BigRat earned 100 total points
ID: 1216173
Yes, you would have an array of PChar :-
const
   MaxCount = 1000;
type
   TNameArray = array[1..MaxCount] of PChar;
var
   NameArray : TNameArray;
   Name        : packed array[0..60 of Char];
   Leng         : Integer;

   Leng:=0;
   while not Eof(Input) do
      begin
      Readln(Input,Name);
      Inc(Leng);
      NameArray[Leng]:=StrNew(Name);
      end;

The elements are then 1..Leng.

For further Info (if you need it) reject this answer.
0
 

Author Comment

by:willie117
ID: 1216174
Thank you for your answer.  It is most helpful.  One last question though (I'm not the best programmer) how do I access the individual elements?  Thanks.  Have ratitude!
0
 

Author Comment

by:willie117
ID: 1216175
I think I asked my question too fast: I think I access the elements with: NameArray[1], NameArray[2], ... or with NameArray[Leng].  
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
change the mouse cursor 1 999
Pascal equivalent of VB Select/case 3 338
delphi custom sort exception 6 135
delphi prevent click fast 2 189
When we talk about DevOps toolchains, I sometimes wonder how many people really get what we’re talking about. I don’t know if it’s just semantics or tone or something else, but sometimes I think it just sounds like buzzword sausage. So it’s always …
We need a new way to communicate time sensitive or critical info.   The best part of my role at xMatters is visiting our clients all over the world to learn about how they operate their businesses, share insights that xMatters has gleaned across…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now