プロが教えるわが家の防犯対策術!

キーボードから「英文」を読み込み、空白(スペース)を英単語の区切りとみなして英単語辞書を整順リスト形式で作りたいのですがうまくいきません。
ソースとコンパイル結果の間違いは↓にありますが、そもそも v := read( sentences ) なんてのが可能なのかもわかりません。(readは最初から一文字ずつ読むとか聞いたのでこうしたのですが・・・)
どなたかご教授ください。

program kadai(input,output);
type list = ^mojirec;
mojirec = record
newword : packed array[1..20] of char;
next : list
end;
var sentences,v : packed array[1..500] of char;
p,head : list;

procedure insert(var p : list; x : packed array[1..20] of char );
var q : list;
begin
if p = nil then begin
new(p);
p^.newword := x;
p^.next := nil
end
else if x < p^.newword then begin
q := p;
new( p );
p^.newword := x;
p^.next := q
end
else
insert( p^.next,x )
end;
procedure print( p : list );
begin
if p<> nil then begin
writeln( p^.newword );
print( p^.next )
end
end;

begin
head := nil;
write('英文:');
readln( sentences );
repeat
repeat
repeat
read( sentences );
v := read( sentences );
until( read('') );
insert( head,v )
until ( read('.') );
writeln('英文:');
until ( sentences = '.' );
print( head )
end.

In program kadai:
E 18240 x undefined on lines 16 19 22 26
E 18240 insert undefined on line 26

終了条件はピリオド単体を読み込んだとき、英文の最後はピリオドを付けるようにとなっています。

A 回答 (1件)

この課題のポイントは、英単語の切り分けとリスト構造の操作(データの比較、挿入、追加)にあるのではないかと思いますが、それ以前にreadの仕様がわからないのでしたら、まずそれをマスターする必要があるでしょう。



私だったら文法のマニュアルを読んだ上で、read,writeだけを使った小さなプログラムを作り、動作を確認します。

Delphiのコンソールプログラムですと read(sentence); で1行読み取ります(sentenceの型はstring)。それがわかれば、次はsentenceを英単語に切り分けてやればよい訳です。

あと、課題のおまけのポイントとして、英大小文字を同一視するか、同じ単語をどう扱うかなどの細かい仕様を詰めるとよいと思います。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!