MAINSAIL Language Manual, Section 36.13

previous   next   top   contents   index   framed top   this page unframed


36.13. getPos

Figure 36–11. getPos
LONG INTEGER
PROCEDURE   getPos      (POINTER(filef);

getPos returns the current position of f, in character units.

Example 36–12. Use of getPos
INTEGER             c,j,k;
LONG INTEGER        pos,savePos;
POINTER(textFile)   f;

open(f,"results",create!random);

Suppose you are writing characters to f and you come to
a point where you know another character is needed,
but you don't yet know its value and you need to
write out other characters before you will know its
value.  You can save the position at which this
character belongs,

savePos := getPos(f);

temporarily write out an "x", sayas a place holder,

cWrite(f,'x');

and then continue writing out other characterse.g.,

write(f,"abc");

. . .

until you know the value of the original character,
say cso you can replace the "xwritten in its place
with the proper value.  Save the current position in f,
position back to the position for the character cwrite
out the desired characterand position back to where
you were to continue writing more characters:

pos := getPos(f);
setPos(f,savePos); cWrite(f,c);
setPos(f,pos);


previous   next   top   contents   index   framed top   this page unframed

MAINSAIL Language Manual, Section 36.13