Napisałeś, że chcesz wydobyć pierwsze słowo i zarówno mój kod jak i kAzka to robi. Jak chcesz podzielić na wyrazy względem separatora to skorzystaj w FPC z modułu Classes i koniecznie dodaj {$MODE DELPHI} żeby się kompilator nie czepiał, że nie wie co to Result. Ewentualnie przerób sobie te funkcje aby dodawała do statycznej albo dynamicznej tablicy stringów.
function Explode(Str : string; Separator : string) : TStringList;
var
X : integer;
begin
Result := TStringList.Create;
X := Pos(Separator, Str);
while X > 0 do
begin
Result.Add(Copy(Str, 1, X - 1));
if X <= Length(Str) then
begin
Str := Copy(Str, X + Length(Separator), Length(Str));
end;
X := Pos(Separator, Str);
end;
if (Length(Str) > 0) then
begin
Result.Add(Str);
end;
end;
W Turbo Pascalu napisałem kiedyś taki przykład. Ale FPC ma już z tego co widze bez problemową obslugę tablic dynamicznych, także jak nie chcesz używac TStringList to sobie poniższy kod przerób dla tablicy dynamicznej, nie jest to problem - wystarczy zwiększać jej rozmiar przez SetLength.
program gles;
const
AFileName = 'D:\data.txt';
LeftChars : array[boolean] of string = (#32, #32#32);
type
TStringArray10 = array[1..10] of string;
var
TF : Text;
S, Line : string;
I, Code : integer;
Arr : TStringArray10;
procedure Explode(Str : string; Separator : string; var AnArr : TStringArray10);
var
I, X : integer;
begin
I := Low(AnArr);
X := Pos(Separator, Str);
while X > 0 do
begin
if I <= High(AnArr) then
begin
AnArr[I] := Copy(Str, 1, X - 1);
I := I + 1;
end;
if X <= Length(Str) then
begin
Str := Copy(Str, X + Length(Separator), Length(Str));
end;
X := Pos(Separator, Str);
end;
if (Length(Str) > 0) then
begin
if I <= High(AnArr) then
begin
AnArr[I] := Str;
end;
end;
end;
begin
Assign(TF, AFileName);
{$I-}
Reset(TF);
{$I+}
if IOResult <> 0 then
begin
Writeln('Nie mozna wczytac lub brak pliku: ', AFileName, '!');
end
else
begin
while not EOF(TF) do
begin
for I := Low(Arr) to High(Arr) do
begin
Arr[I] := '';
end;
Readln(TF, Line);
S := Copy(Line, 1, Pos(#32, Line) - 1);
Val(S, I, Code);
if (Code = 0) and (I <= High(Arr)) then
begin
S := Copy(Line, Pos(#32, Line) + 1, MaxInt);
Explode(S, #32, Arr);
for I := Low(Arr) to High(Arr) do
begin
if Arr[I] <> '' then
begin
Writeln(LeftChars[I < High(Arr)], I, ': ', Arr[I]);
end
else
begin
Break;
end;
end;
Writeln;
end;
end;
Close(TF);
end;
Readln;
end.