Goodmorning Posted August 2, 2010 Report Share Posted August 2, 2010 Witam. Piszę program, który wczytuje z pliku komendy i wykonuje je. Wszystko pięknie działa. Gdy jednak w pliku dwa razy użyję polecenia odwołującego się do read-u pojawia się problem. Program ignoruje drugie użycie tej opcji i leci dalej. Sprawdzałem kod tysiąc razy, mój brat (który też jest na tym forum) również sprawdził. I nic. Odkryliśmy tylko mały błąd w postaci braku średnika na końcu if-ów, ale to nie rozwiązało sprawy. Dam cały kod programu, ponieważ uważam że problem nie tkwi w samym if-ie który wykonuje procedurę read. uses crt,dos; var nazwa:string; var tekstowka:text; var polecenie:string; var info:string; var a:string; var b:string; var c:string; var d:string; var l:array[1..5] of integer; var kod:integer; begin if ParamCount=1 then nazwa:=ParamStr(1); assign(tekstowka,nazwa); reset(tekstowka); repeat readln(tekstowka,polecenie); if (polecenie='H') or (polecenie='h') or (polecenie='Helloworld!') or (polecenie='helloworld!') then write('Hello World!') else if (polecenie='Napisz!') or (polecenie='napisz!') or (polecenie='Write!') or (polecenie='write!') then begin readln(tekstowka,info); if info='a' then write(a) else if info='b' then write(b) else if info='c' then write(c) else if info='d' then write(d) else write(info); end else if (polecenie='Czekaj!') or (polecenie='czekaj!') or (polecenie='Wait!') or (polecenie='wait!') then begin readln(tekstowka,info); if info='a' then begin val(a,l[1],kod); l[1]:=l[1] * 1000; delay(l[1]) end else if info='b' then begin val(b,l[2],kod); l[2]:=l[2] * 1000; delay(l[2]) end else if info='c' then begin val(c,l[3],kod); l[3]:=l[3] * 1000; delay(l[3]) end else if info='d' then begin val(b,l[4],kod); l[4]:=l[4] * 1000; delay(l[4]) end else begin val(info,l[5],kod); l[5]:=l[5] * 1000; delay(l[5]); end; end else if (polecenie='Linia!') or (polecenie='linia!') or (polecenie='Enter!') or (polecenie='enter!') or (polecenie='Line!') or (polecenie='line!') then writeln else if (polecenie='zapytaj!') or (polecenie='Zapytaj!') or (polecenie='Ask!') or (polecenie='ask!') then begin readln(tekstowka,info); if info='a' then read(a) else if info='b' then read(b) else if info='c' then read(c) else if info='d' then read(d); end else if (polecenie='Pauza!') or (polecenie='pauza!') or (polecenie='Stop!') or (polecenie='stop!') or (polecenie='Pause!') or (polecenie='pause!') then readkey else if polecenie='a' then begin readln(tekstowka, info); a:=info; end else if polecenie='b' then begin readln(tekstowka, info); b:=info; end else if polecenie='c' then begin readln(tekstowka, info); c:=info; end else if polecenie='d' then begin readln(tekstowka, info); d:=info; end else if (polecenie='czysc!') or (polecenie='Czysc!') or (polecenie='Clear!') or (polecenie='clear!') then clrscr; until(polecenie=''); writeln; writeln; write('Koniec programu'); readkey; end. Link to comment Share on other sites More sharing options...
Adam27 Posted August 2, 2010 Report Share Posted August 2, 2010 A czy jesteś pewien, że zarówno polecenia jak i "argumenty" tych poleceń są w osobnych liniach? Bo procedura 'readln' wczytuje do stringa całą linię, a nie tylko jeden wyraz. Etharnion - 2D RPG Szukam grafika chętnego do współpracy przy projekcie. Link to comment Share on other sites More sharing options...
Goodmorning Posted August 2, 2010 Author Report Share Posted August 2, 2010 Oczywiście w plikach polecenia i te argumenty są w osobnych liniach. Link to comment Share on other sites More sharing options...
Adam27 Posted August 2, 2010 Report Share Posted August 2, 2010 To pokaż ten plik tekstowy i napisz, której linijki Ci nie chce wykonać. Etharnion - 2D RPG Szukam grafika chętnego do współpracy przy projekcie. Link to comment Share on other sites More sharing options...
Goodmorning Posted August 2, 2010 Author Report Share Posted August 2, 2010 KOD napisz! Pierwsze slowo: zapytaj! a linia! napisz! Drugie slowo: zapytaj! b Czysc! napisz! a linia! napisz! b Program od razu powtarza słowo, czyli nie bierze pod uwagę linijek od 3 do 9. EDIT Zapomniałem, że jest tam instrukcja "Czysc!" To dlatego nie pokazuje napisu "Drugie slowo". Link to comment Share on other sites More sharing options...
Adam27 Posted August 2, 2010 Report Share Posted August 2, 2010 Tam gdzie masz w kodzie "zapytaj" zamiast read'ów postaw readln'y. Etharnion - 2D RPG Szukam grafika chętnego do współpracy przy projekcie. Link to comment Share on other sites More sharing options...
Goodmorning Posted August 2, 2010 Author Report Share Posted August 2, 2010 Nadal nie działa. Zmieniłem te ready na readlny. Link to comment Share on other sites More sharing options...
Adam27 Posted August 2, 2010 Report Share Posted August 2, 2010 Skopiowałem sobie Twój kod i dane do pliku i u mnie z readlnami działa - najpierw pyta o dwie dane, potem je wyświetla. Nie wiem co jeszcze jest źle. Etharnion - 2D RPG Szukam grafika chętnego do współpracy przy projekcie. Link to comment Share on other sites More sharing options...
Goodmorning Posted August 2, 2010 Author Report Share Posted August 2, 2010 Może to przez mój porąbany kompilator Dev Pascal. Spróbuję na Lazarusie. EDIT Zapomniałem dodać readln-a w if-ie od a . Wszystko działa. Dziękuję za pomoc. Temat do zamknięcia. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.