Pascal read command - pascal

I built a program in pascal using FPC but after this I installed lazarus. So now I'm editing this same pascal program in Lazarus.
It works very well to insert, modify and list: name, surname and telephone in a array of record of this type.
But the read command is not working for me in this modify procedure.
But the read command works well on my Delete procedure for example.
Main problem:
**These 3 read command did not work so I modified to readln which fixed it for me and now each one reads my inputs but only with readln, but not with read. **
But why ?
gotoxy(24,8);
read(modificar_nome);
gotoxy(24,9);
read(modificar_sobrenome);
gotoxy(24,10);
read(modificar_telefone);
Complete Procedure
//---------------------------------------
// MODIFICAR escolha
//---------------------------------------
procedure modificar_pessoa(var pessoa: type_pessoas);
var i,achou: integer;
var buscar_pessoa, modificar_nome, modificar_sobrenome, modificar_telefone: string;
begin
clrscr;
writeln('****************************************************************************************');
writeln('* Modificar pessoa *');
writeln('****************************************************************************************');
writeln('* Nome: *');
writeln('****************************************************************************************');
gotoxy(9,4); readln(buscar_pessoa);
for i:=0 to length(pessoa)-1 do
begin
if (pessoa[i].primeiro_nome = buscar_pessoa) then
begin
achou := 1;
break;
end;
end;
if achou = 1 then
begin
writeln('****************************************************************************************');
writeln('* Preencher so o que deseja modificar (ou ENTER para ignorar): *');
writeln('****************************************************************************************');
writeln('* Novo Primeiro Nome? *');
writeln('* Novo Sobrenome? *');
writeln('* Novo Telefone? *');
writeln('****************************************************************************************');
gotoxy(24,8);
read(modificar_nome); // not waiting for my input ???????????
gotoxy(24,9);
read(modificar_sobrenome);
gotoxy(24,10);
read(modificar_telefone);
if modificar_nome <> '' then
pessoa[i].primeiro_nome := modificar_nome;
if modificar_sobrenome <> '' then
pessoa[i].ultimo_nome := modificar_sobrenome;
if modificar_telefone <> '' then
pessoa[i].telefone := modificar_telefone;
gotoxy(1,13);
writeln;
writeln('Pessoa ''', buscar_pessoa, ''' modificada com sucesso!');
end
else
begin
gotoxy(1,13);
writeln;
writeln('ERRO: Pessoa ''', buscar_pessoa, ''' não foi localizada!');
end;
writeln;
writeln('Pressione qualquer tecla para retornar ao menu...'); ReadAnyKey;
end;
Funny is this other procedure to delete (exclude) people, the read command works fine and waits for my input
//---------------------------------------
// EXCLUIR escolha
//---------------------------------------
procedure excluir_pessoa(var pessoa: type_pessoas);
var i,achou: integer;
var del_pessoa: string;
begin
clrscr;
writeln('****************************************************************************************');
writeln('* Excluir pessoa *');
writeln('****************************************************************************************');
writeln('* Nome: *');
writeln('****************************************************************************************');
gotoxy(9,4); read(del_pessoa);
for i:=0 to length(pessoa)-1 do
begin
if (pessoa[i].primeiro_nome = del_pessoa) then
begin
achou := 1;
pessoa[i].primeiro_nome := '';
pessoa[i].ultimo_nome := '';
pessoa[i].telefone := '';
break;
end;
end;
gotoxy(1,6);
if achou = 1 then
writeln('Pessoa ''', del_pessoa, ''' excluida com sucesso!')
else
writeln('ERRO: Pessoa ''', del_pessoa, ''' nao foi localizada!');
writeln;
writeln('Pressione qualquer tecla para retornar ao menu...'); ReadAnyKey;
end;

I think that the short answer to this is that your observation is correct and that the reason is that Read is working as designed. Once FPC's runtime has executed the firstRead it behaves as if it has seen an Eol after what the user typed, and therefore the second and subsequent calls to Read return immediately without waiting for any further user input.
The reason it behaves this was seems to be historical. FPC was based on the Object Pascal of the commercial RAD system Delphi, and although the two have diverged somewhat over the years (e.g. in their different implementations of generics), FPC faithfully reproduces many of the basic details of the Object Pascal language and runtime, including its file handling, of which keyboard input is a special case.
I think that it is legitimate. therefore, to look at the Delphi/Object Pasval documentation of Read. In the online help of Delphi 7, which dates from 20 years ago, the section on Read includes
Description
The Read procedure can be used in Delphi code in the following ways.
For typed files, it reads a file component into a variable.
For text files, it reads one or more values into one or more variables.
With a type string variable:
Read reads all characters up to, but not including, the next end-of-line marker or until Eof(F) becomes true; it does not skip to the next line after reading. If the resulting string is longer than the maximum length of the string variable, it is truncated.
After the first Read, each subsequent Read sees the end-of-line marker and returns a zero-length string.
Use multiple Readln calls to read successive string values.[emphasis added]
So, the Delphi OLH documents exactly the behaviour you are seeing (that the second and subsequent calls to Read return immediately without gathering any user input) and describes the remedy, which is to use Readln instead. And that's why you see the same behaviour + remedy in FPC.

Related

Program in pascal [duplicate]

This question already has answers here:
What is that the Error of Illegal assignment and how to correct it?
(2 answers)
Closed last month.
Just started to learn the Pascal programming language, I wrote an assignment that was given at the university, here is my assignment:
Build a program that will perform the following actions:
retrieve data of N elements (brand, name, atomic weight, density)
find the average density value
finding the three elements with the lowest atomic mass
writing the inputs and outputs to the text file "elements.txt"
wrote code for it, in theory everything should work, but it gives out some strange errors, if I have standard errors, I apologize for them.
program MINERALY_;
uses Crt;
const NMAX=200;
type MINERAL=record
NAZOV:string;
HUST:real;
ATOM:real;
ZNACKA:real;
end;
MINERALY=array[1..NMAX] of MINERAL;
var N,i,C,D:integer;
V:real;
MI:MINERALY;
S:string;
SUB:text;
PTVRD,CTVRD:real;
MINATOM:real;
begin
ClrScr;
Writeln('Program pre nacitanie mineralov a vypocet hodnot ich jednotlivych
vlastnosti.');
Writeln('===============================================================================');
{Vynulovanie hodnot}
CTVRD:=0;
PTVRD:=0;
MINATOM:=0;
{Nacitanie poctu mineralov}
Writeln;
Write('Zadajte pocet nacitavanych mineralov (Maximalne 200): ');
repeat
Readln(S);
Val(S,D,C);
if (C<>0) or (D<=0) or (D>200) then
begin
Writeln;
Writeln('Zadali ste nespravny pocet, alebo ste zadali nespravne znaky !');
Writeln('Hodnota moze byt od 1-200');
Write('Zadajte pocet mineralov este raz: ');
end;
N:=D;
until(N>0) and (N<=200) and (C=0);
{nacitavanie udajov, zistovanie max. a min. hodnot atd.}
for i:=1 to N do
begin
Writeln;
Write('Zadajte Znacku: ');
Readln(MI[i].ZNACKA);
Writeln;
Write('Zadajte nazov: ');
Readln(MI[i].NAZOV);
Write('Zadajte hustotu (musi byt vacsia ako 0): ');
repeat
Readln(S);
Val(S,V,C);
if (C<>0) or (V<0) then
begin
Writeln;
Writeln('Zadali ste nespravnu hodnotu, alebo ste zadali nespravne znaky !');
Write('Zadajte hustotu este raz (musi byt vacsia ako 0): ');
end;
until (V>0) and (C=0);
MI[i].HUST:=V;
CTVRD:=CTVRD+MI[i].HUST;
Write('Zadajte atómovou hmotnosťou (musi byt vacsia ako 0): ');
repeat
Readln(S);
Val(S,V,C);
if (C<>0) or (V<0) then
begin
Writeln;
Writeln('Zadali ste nespravnu hodnotu, alebo ste zadali nespravne znaky !');
Write('Zadajte atómovou hmotnosťou este raz (musi byt vascia ako 0): ');
end;
until (V>0) and (C=0);
MI[i].ATOM:=V;
if (i=1) then MINATOM:=MI[i].ATOM;
if (MI[i].ATOM<MINATOM) then MINATOM:=MI[i].ATOM;
PTVRD:=CTVRD/N;
Writeln;
Writeln('Vypocitane hodnoty: ');
Writeln('===================================');
Writeln;
Writeln('Priemerna tvrdost mineralov: ',PTVRD:2:2);
Writeln('Najnizsia hustota: ',MINATOM:2:2);
Assign(SUB,'mineral.txt');
Rewrite(SUB);
Writeln(SUB,'Nacitane mineraly: ');
Writeln(SUB,'===================================');
Writeln(SUB,'');
for i:=1 to N do
begin
Writeln(SUB,i,'. mineral: ');
Writeln(SUB,'Nazov: ',MI[i].NAZOV);
Writeln(SUB,'Znacka: ',MI[i].ZNACKA);
Writeln(SUB,'Tvrdost: ',MI[i].HUST:2:2);
Writeln(SUB,'Hustota: ',MI[i].ATOM:2:2);
Writeln(SUB,'');
end;
Writeln(SUB,'===================================');
Writeln(SUB,'Vypocitane hodnoty: ');
Writeln(SUB,'===================================');
Writeln(SUB,'');
Writeln(SUB,'Priemerna tvrdost mineralov: ',PTVRD:2:2);
Writeln(SUB,'Najnizsia hustota: ',MINATOM:2:2);
Close(SUB);
Writeln;
Writeln;
Writeln('Pre ukoncenie programu stlacte ENTER !');
Readln;
end.
Here are the errors this code gives me:
Compiling main.pas
main.pas(109,14) Error: Illegal assignment to for-loop variable "i"
main.pas(132,4) Fatal: Syntax error, ";" expected but "." found
Fatal: Compilation aborted
Error: /usr/bin/ppcx64 returned an error exitcode
Error: Illegal assignment to for-loop variable "i"
is when you are trying to change the value of i while the loop is still working.
since you didn't end; the loop you canno't change the value of i you can use another variable, j for example, unless your first for-loop is over and you forgot the end; key

Delphi 7 - Checking a Letter with TMemo.Lines

I currently have set of words inputted inside my MemoBox.
Question is how do I check the specific letters on each lines of the TMemobox Lines property. If letter is not similar on the word being specified then it should be wrong and not be counted in and if answer correct how to let the word appear on the wordlabel?
Also how to limit the guess-label property into only inputting 5 letters?
Currently making a hang-man game :)
Set of Words here
I currently have this code:
{***************** CheckALetter ***************}
procedure TForm1.CheckLetter(ch:char);
var
i:integer;
s:string;
goodguess:boolean;
begin
goodguess:=false;
if not (ch in GuessedLetters)
then
begin
GuessedLetters:=GuessedLetters+[ch];
guessesLabel.caption:=guesseslabel.caption+ch+',';
s:=Wordlabel.caption;
for i:=1 to length(TheWord) do {see if the letter is in the word}
begin
if ch=Theword[i] then
begin
s[2*i-1]:=ch; {fill in the letter in display}
goodguess:=true;
end;
end;
wordlabel.caption:=s;
{if not goodguess then drawAPiece(clred);}
If pos('_',WordLabel.caption)=0 then {all underscores replaced by letters}
showmessage('A reprieve!')
else {If piececount=Hangmanlist.count}
begin
showmessage('Oh, oh Goodbye!'+#13 +'(The word was '+theword+')');
{deadlbl.visible:=true;}
end;
end
else messagebeep(mb_IconExclamation);
end;
//On key presss
procedure TForm1.guess_typeKeyPress(Sender: TObject; var Key: Char);
begin
key:=upcase(key);
guess_type.text:='';
If not (key in ['A'..'Z']) then
begin
key:=#00;
messagebeep(mb_iconexclamation);
end
else CheckLetter(key);
end;
end.
not sure where the TMemo fits in. The TMemo.Lines is just a normal TStringList, you can make a fo
for i:=1 to MyMemo.Lines.Count do
s := MyMemo.Lines[i-1];
// Do somenthing with s..

Wrong use of 'file of char'

Im having problems with this code, I have two file of char, one is filed with information about books, and the other is empty, i have to write in SAL some information from S and then show the total of how many books match the first 2 digits of the code and how many are R and how many are T. The code, does write the information form S to Sal, but when its supposed to show the totals it appears ERORR 100 on screen. I read about it and it says that it is a problem with 'Disk read error' and that *This error typically occurs, if you "seed" a non-existent record of a typed file and try to read/write it. *, i really dont undertand.
I've benn trying to figure it out, but I haven't been able to. I notice that if I dont put 'WHILE NOT EOF(S) DO' the error does not appear, but of course i need the while, if someone is able to point out my mistakes i would really apreciate it.
This is the code:
uses crt;
var
i : byte;
s,sal: file of char;
v,l1,l2: char;
cs,cn,cl: integer;
pn,ps,tot: integer;
BEGIN
cs:=0; cn:=0; i:=0; cl:=0;
Assign (s, 'C:\Users\te\Documents\s.txt');
{$I-}
Reset (s);
{$I+}
if IOResult <> 0 then
begin
writeln('Error');
halt(2);
end;
Assign (sal, 'C:\Users\te\Documents\sal.txt');
{$I-}
Rewrite (sal);
IOResult;
{$I+}
if IOResult <> 0 then
halt(2);
writeln('Please write the code of the book, only 2 digits');
read(L1);read(L2);
read(s,v);
while (not eof(s)) do
begin
for i:=1 to 2 do
read(s,v);
if (v = '0') then
begin
read(s,v);
if (v = '1') or (v = '2') then
begin
for i:=1 to 5 do
read(s,v);
if (v = 'R') then
begin
read(s,v);
cs:= cs + 1;
end
else
begin
if (v = 'T') then
begin
cn:= cn + 1;
read(s,v);
end;
end;
while (v <> '-') do
read(s,v);
while (v = '-') do
read(s,v);
if (v = L1) then
begin
write(sal, v);
read(s,v);
if (v = L2) then
begin
write(sal,v);
read(s,v);
cl:= cl + 1;
end;
end;
while ( v <> '/') do
begin
write(sal,v);
read(s,v);
end;
write(sal, '-');
end
else
begin
for i:= 1 to 5 do
read(s,v);
if (v = 'R') then
cs:= cs + 1
else
cn:= cn + 1;
if (v = L1) then
read(s,v);
if (v = L2) then
begin
cl:= cl + 1;
read(s,v);
end;
end;
end
else
begin
for i:= 1 to 5 do
read(s,v);
if (v = 'R') then
cs:= cs + 1
else
cn:= cn + 1;
if (v = L1) then
read(s,v);
if (v = L2) then
begin
cl:= cl + 1;
read(s,v);
end;
end;
end;
tot:= cs + cn;
ps:= (cs * 100) div tot;
pn:= (cn * 100) div tot;
writeln('TOTAL ',cl);
writeln();
writeln(ps,'% and',pn,'%');
The file S content:
02022013Rto kill a mockingbird-1301/02012014Tpeter pan-1001/02032013Thowto-2301/02012012Tmaze runner-1001/02012012Tmaze runner-1001/02012012Tmaze runner-1001/$
I really just need someone else's point of view on this code, I think maybe the algorithm is flawed.
Thanks
(After your edit, i see that your code now compiles w/o error in FPC, so I'm glad you've managed to fix the error yourself)
As this is obviously coursework, I'm not going to fix your code for you and in any case the wayEven so, I'm afraid you are going about this is completely wrong.
Basically, the main thing wrong with your code is that you are trying to control what happens as your read the source file character by character. Quite frankly, that's a hopeless way of trying to do it, because it makes the execution flow unnecessarily complicated and littered with ifs, buts and loops. It also requires you to keep mental track of what you are trying to do at any given step, and the resulting code is inherently not self-documenting - imagine if you came back to your code in six months, could you tell at a glance how it works and what it does? I certsinly couldn't personally.
You need to break the task down in a different way. Instead of analysing the problem from the bottom up ("If I read this character next, then what I need to do next is ...') do it from the top down: Although your input file is a file of char, it contains a series of strings, separated by a / character and finally terminated by a $ (but this terminator does not really matter). So what you need to do is to read these strings one-by-one; once you've got one, check whether it's the one you're looking for: if it is. process it however you need to, otherwise read the next one until you reach the end of the file.
Once you have successfully read one of the book strings, you can then split it up into the various fields it's composed of. The most useful function for doing this splitting is probably Copy, which lets you extract substrings from a string - look it up in the FPC help. I've included functions ExtractTitle and ExtractPreamble which show you what you need to do to write similar functions to extract the T/R code and the numeric code which follows the hyphen. Btw, if you need to ask a similar q in the future, it would be very helpful if you include a description of the layout and meaning of the various fields in the file.
So, what I'm going to show you is how to read the series of strings in your S.Txt by building them character-by-character. In the code below, I do this using a function GetNextBook which I hope is reasonable self-explanatory. The code uses this function in a while loop to fill the BookRecord string variable. Then, it simply writes the BookRecord to the console. What your code should do, of course, is to process the BookRecord contents to see if it is the one you are looking for and then do whether the remainder of your task is.
I hope you will agree that the code below is a lot clearer, a lot shorter and will be a lot easier to extend in future than the code in your q. They key to structuring a program this way is to break the program's task into a series of functions and procedures which each perform a single sub-task. Writing the program that way makes it easier to "re-wire" the program to change what it does, without having to rewrite the innards of the functions/procedures.
program fileofcharproject;
uses crt;
const
sContents = '02022013Rto kill a mockingbird-1301/02012014Tpeter pan-1001/02032013Thowto-2301/02012012Tmaze runner-1001/02012012Tmaze runner-1001/02012012Tmaze runner-1001/$';
InputFileName = 'C:\Users\MA\Documents\S.Txt';
OutputFileName = 'C:\Users\MA\Documents\Sal.Txt';
type
CharFile = File of Char; // this is to permit a file of char to be used
// as a parameter to a function/procedure
function GetNextBook(var S : CharFile) : String;
var
InputChar : Char;
begin
Result := '';
InputChar := Chr(0);
while not Eof(S) do begin
Read(S, InputChar);
// next, check that the char we've read is not a '/'
// if it is a '/' then exit this while loop
if (InputChar <> '/') then
Result := Result + InputChar
else
Break;
end;
end;
function ExtractBookTitle(BookRecord : String) : String;
var
p : Integer;
begin
Result := Copy(BookRecord, 10, Length(BookRecord));
p := Pos('-', Result);
if p > 0 then
Result := Copy(Result, 1, p - 1);
end;
procedure AddToOutputFile(var OutputFile : CharFile; BookRecord : String);
var
i : Integer;
begin
for i := 1 to Length(BookRecord) do
write(OutputFile, BookRecord[i]);
write(OutputFile, '/');
end;
function ExtractPreamble(BookRecord : String) : String;
begin
Result := Copy(BookRecord, 1, 8);
end;
function TitleMatches(PartialTitle, BookRecord : String) : Boolean;
begin
Result := Pos(PartialTitle, ExtractBookTitle(BookRecord)) > 0;
end;
var
i : Integer; //byte;
s,sal: file of char;
l1,l2: char;
InputChar : Char;
BookFound : Boolean;
cs,cn,cl: integer;
pn,ps,tot: integer;
Contents : String;
BookRecord : String;
PartialTitle : String;
begin
// First, create S.Txt so we don't have to make any assumptions about
// its contents
Contents := sContents;
Assign(s, InputFileName);
Rewrite(s);
for i := 1 to Length(Contents) do begin
write(s, Contents[i]); // writes the i'th character of Contents to the file
end;
Close(s);
cs:=0; cn:=0; i:=0; cl:=0;
// Open the input file
Assign (s, InputFileName);
{$I-}
Reset (s);
{$I+}
if IOResult <> 0 then
begin
writeln('Error');
halt(2);
end;
// Open the output file
Assign (sal, OutputFileName);
{$I-}
Rewrite (sal);
IOResult;
{$I+}
if IOResult <> 0 then
halt(2);
// the following reads the BookRecords one-by-one and copies
// any of them which match the partial title to sal.txt
writeln('Enter part of a book title, followed by [Enter]');
readln(PartialTitle);
while not Eof(s) do begin
BookRecord := GetNextBook(S);
writeln(BookRecord);
writeln('Preamble : ', ExtractPreamble(BookRecord));
writeln('Title : ', ExtractBookTitle(BookRecord));
if TitleMatches(PartialTitle, BookRecord) then
AddToOutputFile(sal, BookRecord);
end;
// add file '$' to sal.txt
write(sal, '$');
Close(sal);
Close(s);
writeln('Done, press any key');
readln;
end.

how to get a variable out of a procedure in the right way in PASCAL?

I'm following an internet course on the basics of programming. After making a diagram I convert it to code, right now this is PASCAL language.
I'm having a problem with procedures and can't find an answer, nor in the course, nor with some google-ing.
I want to get a variavble back form a procedure. Right now iIhave a working piece of code but I think this is not the good way of working. Here's an extract of the code:
program WELKEWAGEN;
// declare your variables here
var T, N, KM, vari, prijsDW, prijsBW, jrenGEBR, taksDW, taksBW, prijsB, verbrBW, prijsD, verbrDW : real;
procedure OPHALEN(para : string);
begin
repeat
writeln('geef de ', para , ' op');
readln(vari);
until (vari > 0);
end;
begin
//this is the main program but there is more code ofcourse
OPHALEN('prijs benzinewagen');
prijsBW := vari;
//...
end.
Now the internet course says I should program it like this:
begin
//...
prijsBW := OPHALEN('prijs benzinewagen');
//...
end.
But this is not working.
I get following errors:
WELKEWAGEN.pas(24,14) Error: Incompatible types: got "untyped" expected "Real"
WELKEWAGEN.pas(50) Fatal: There were 1 errors compiling module, stopping
pas(24,14) is this line: prijsBW := OPHALEN('prijs benzinewagen');
Procedures don't return values, so the syntax
prijsBW := OPHALEN('prijs benzinewagen');
is invalid.
If you want to return a value, you need to define a function instead:
function OPHALEN(para : string): Real;
var
Res: Real;
begin
Res := 0;
repeat
writeln('geef de ', para , ' op');
readln(Res);
until (Res > 0);
OPHALEN := Res;
end;
Note that the (bad) global variables you're using mean you don't have to return anything at all, because a procedure can access and change that global variable directly (but you have no way of knowing when the procedure is finished):
procedure OPHALEN(para : string);
begin
vari := 0;
repeat
writeln('geef de ', para , ' op');
readln(vari);
until (vari > 0);
end;
Modern Pascal dialects (such as Delphi and FreePascal) allow a cleaner syntax for the return value of functions by using an automatically declared function result variable of the proper type for you, named Result (because that's what it is - the result of the function):
function OPHALEN(para : string): Real;
begin
Result := 0;
repeat
writeln('geef de ', para , ' op');
readln(Result);
until (Result > 0);
end;
If you need to return multiple values, you can use var parameters, which allow them to be changed inside the function.
procedure OPHALEN(para: string; var RetVal: Real);
begin
RetVal := 0;
repeat
writeln('geef de ', para , ' op');
readln(RetVal);
until (RetVal > 0);
end;
Your original code (and the examples I've provided above) all fail to allow the user to cancel, BTW. There should be some way to exit the loop for the user; otherwise, your code just endlessly loops, writing para to the screen and then waiting for input. This has a tendency to annoy users.

Reading integer numbers in Pascal

I'm using Pascal. I have a problem when dealing with reading file.
I have a file with integer numbers. My pascal to read the file is:
read(input, arr[i]);
if my file content is 1 2 3 then it's good but if it is 1 2 3 or 1 2 3(enter here) (there is a space or empty line at the end) then my arr will be 1 2 3 0.
From what I can recall read literally reads the file as a stream of characters, of which a blank space and carriage return are, but I believe these should be ignored as you are reading into an integer array. Does your file actually contain a space character between each number?
Another approach would be to use readLn and have the required integers stored as new lines in the file, e.g.
1
2
3
I have tested the problem on Delphi 2009 console applications. Code like this
var
F: Text;
A: array[0..99] of Integer;
I, J: Integer;
begin
Assign(F, 'test.txt');
Reset(F);
I:= -1;
while not EOF(F) do begin
Inc(I);
Read(F, A[I]);
end;
for J:= 0 to I do write(A[J], ' ');
Close(F);
writeln;
readln;
end.
works exactly as you have written. It can be improved using SeekEOLN function that skips all whitespace characters; the next code does not produce wrong additional zero:
var
F: Text;
A: array[0..99] of Integer;
I, J: Integer;
begin
Assign(F, 'test.txt');
Reset(F);
I:= -1;
while not EOF(F) do begin
if not SeekEOLN(F) then begin
Inc(I);
Read(F, A[I]);
end
else Readln(F);
end;
for J:= 0 to I do write(A[J], ' ');
Close(F);
writeln;
readln;
end.
Since all that staff is just a legacy in Delphi, I think it must work in Turbo Pascal.
You could read the string into a temporary and then trim it prior to converting it.
It doesnt hurt to mention basics like what type of Pascal on what platform you're using in order that people can give a specific answer (as the article notes, there isnt a nice way OOTB in many Pascals)
If I recall there was a string function called Val that converts a string to a number...my knowledge of Pascal is a bit rusty (Turbo Pascal v6)
var
num : integer;
str : string;
begin
str := '1234';
Val(str, num); (* This is the line I am not sure of *)
end;
Hope this helps,
Best regards,
Tom.

Resources