Solved

About pointers (basics)

Posted on 2004-04-11
1
168 Views
Last Modified: 2010-04-16
Hi everyone,

i'm following the online tutorial that is found on http://www.geocities.com/codeteacher/ i'm at the second lesson, chapter 1. In the previous lesson we had to write a program able to store a textfile in an array and then writing it on the screen. We had also to provide some "browse" features to allow the user to read the whole text using the arrow keys and the page and page down. I did it (may sound like very usual stuff for you but for me it's more dificult).
the program looks like the following

Procedure OpenReadme;
{Procedure that read the 400 first lines of the textfile into an array}
Procedure WriteHeader;
{Procedure that made a kind of menu bar above}
Procedure PageUp;
Procedure PageDown;
Procedure LinUp;
Procedure LineDown;
Procedure DisplayText;

in the Procedure DisplayText there is somehting like this

TempChar:=Readkey
CASE Ord(TempChar) OF
 85:PageUp;
 48:PageDown;
 32:LineUp;
 25:LineDown;
End;

{Head Program}
BEGIN
 OpenReadme;
 WriteHeader;
 DisplayText;
END.

Well that is the shape of the program, it whole works.
but now in that lesson, we have to make the same program AND store the data using pointers. And that is were i'm stuck right now. I have no idea how i should store it in a pointer.

should i make a pointer-array ?

Type
 PText:^TText;
 TText:Array[1..400] Of String;
Var
 WholeText:PText;

??? no i can't do that because we have to allow the user to see the WHOLE text and not only the 400 first lines

i taught of another solution;
store line by line into a generic pointer, if i understood correctly generic pointer have no type, so it is like the 'variant' type in visual basic. i think it is possible, than we have one dynamic variable containing the whole text file, but how should i use that variable to display the text and allow browsing in it ???

CAN SOMEONE PLEASE HELP ME OUT OF THAT ???

Elvis
0
Comment
Question by:Elvis1
1 Comment
 
LVL 1

Accepted Solution

by:
xtremecris earned 100 total points
ID: 10801275
You could try something like this:
Type
 TText:array[1..100] Of PText;
 PText:^TText;
 TText:Array[1..400] Of String;

That means: there is an array of pointers to a TText structure which you can access more easily with an function like this:

function GetLine(Number:Integer):string;
begin
 GetLine:=TText[((Number-1) div 400)+1]^[((Number-1) mod 400)+1];
end;

You might not understand all the indices, they are correct but harder to explain(you should try with a piece of paper to figure them out for your self).

Everything would be a lot easier to understand and a lot faster and run-time if you do it like this:

Type
 tText : array[0..16383] Of ^String;

When you acces the line N from the file it's simply:
                   tText[N]^

This way you have little modifications to do to your original program and there are 16.384 lines of file in memory.This way it's safe to assume that you can read the whole file in memory, in fact if you use TPascal or BPascal you can't actually hope to read more then this.

If you have more questions don't hesitate to ask.

Best regards,
Cris.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Most MSPs worth their salt are already offering cybersecurity to their customers. But cybersecurity as a service is wide encompassing and can mean many things.  So where are MSPs falling in this spectrum?
The advancement in technology has been a great source of betterment and empowerment for the human race, Nevertheless, this is not to say that technology doesn’t have any problems. We are bombarded with constant distractions, whether as an overload o…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 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