pascal - FPC exitcode 201 while using ansistring. String does not do that -


i have question. wrote little program , working perfectly, until changed s , s2 string ansistring. need use ansistring, because way longer 255 characters. response.

    {$h+} program test; uses crt; var s,s2:string;     konec,radek:boolean;     i,a,z:integer; begin   clrscr;   s:='';   s2:='';   i:=0;   a:=0;   z:=1;   konec:=false;   radek:=false;   repeat     s2:='';     readln(s2);     s:=s+s2;   until s2='';   while konec=false begin     while radek=false begin       a:=a+1;       if length(s)+1=a begin         radek:=true;         s:='';         if a<60 writeln(s2);          end;       if not (a=length(s)+1) begin       if s[a]=' '         i:=a;       s2:=s2+s[a];       if not (s[a]=' ')       if a=60 begin         radek:=true;         delete(s2,i,60-i+1);         writeln(s2);         s2:='';         delete(s,z,i);       end;       if (s[a]=' ') , (a=60) begin         radek:=true;     writeln(s2);     s2:='';     delete(s,z,i);       end;       end;     end;     radek:=false;     a:=0;     if (s='') konec:=true;   end;   readkey; end. 

the core thing know shortstring has no problem out of bounds string access (s[a] when not in allowed range (a>=1) , (a<=length(s)) )

you set s '' in code:

 if length(s)+1=a begin     radek:=true;     s:='';     if a<60 writeln(s2);      end; 

but don't reset "a". following condition true , s[a] access bombs out.

  if not (a=length(s)+1) begin   if s[a]=' '     i:=a; 

how solve left exercise reader.

learn use range checks , find issues in minute (hint add -cr -gl commandline)


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -