Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

closed strtoint in pascal?

+4 votes
asked Dec 2, 2020 by Faishal Kemal (170 points)
closed Apr 18, 2022 by Admin
my teacher said that i need to use strtoint in my pascal code

but it said that the identifier not found 'strtoint'

this is my code

program kelaslabor;

var
    sBufer:string[5];
    d,m:integer;

begin
    writeln('write date on DD:MM');
    readln(sBufer);
    writeln(sBufer);
    
    {d:=strtoint(sBufer[1])*10 + strtoint(sBufer[2]);
    m:=strtoint(sBufer[4])*10 + strtoint(sBufer[5]);
    writeln(d,' ',m);}

    d:=strtoint(Copy(sBufer,1,2));
    m:=strtoint(Copy(sBufer,4,2));
    writeln(d,'~',m);

end.
closed with the note: answered

4 Answers

0 votes
answered Dec 2, 2020 by Peter Minarik (86,040 points)
Last time I wrote something in Pascal was about 25 years ago, rofl.

Did you miss an include?

Maybe this one helps: https://www.freepascal.org/docs-html/rtl/sysutils/strtoint.html
+1 vote
answered Apr 6, 2021 by root (810 points)

strToInt is not standardized, but readStr is (in ISO 10206 “Extended Pascal”). You can use readStr pretty much like a regular read/readLn:

readStr('123456', i);

Where i is the name of an integer variable. The string could be of course the name of a (string) variable as well, it doesn’t need to be a constant string literal.

commented Apr 7, 2021 by Peter Minarik (86,040 points)
Good point! I'm glad someone knows their way around  Pascal. :)
0 votes
answered Aug 28, 2021 by abd11a (260 points)

Use val()

https://onlinegdb.com/66vqhA_lQ

//abd11a
function strtoint( s:string ):longint;
  var err:integer; i:longint;
  begin
       val(s,i,err);
       strtoint:=i;
  end;

var x:longint;
begin
    x := strtoint('12');
    writeln(x);

end.
0 votes
answered Apr 16, 2022 by Suren Nanayakkara (140 points)

You need to import the sysutils into your program.

program kelaslabor;
Uses sysutils;
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...