Hi people,
I am a real beginner in programming and I have one (propably super stupid) question:
I am using Standard Pascal (ISO 7185) and want a user to enter, lets say his name and then write it on the screen.
How do I do that without string (since I cant use that in Standard Pascal)?
Array? But how?
program name;
uses crt;
var
name : array[?] of char;
begin
clrscr;
write('Please enter your name: ');
readln(?);
writeln('Your name is', ?);
end.
I know, kinda stupid program. Its just for understanding the basic function.
Would be cool if someone could complete this for me.
Im using TP5.5 (but I may not use the abilities of Turbo. School, you know :-( )
Thanx in advance
Marcus
Comments
:
: I am a real beginner in programming and I have one (propably super stupid) question:
:
: I am using Standard Pascal (ISO 7185) and want a user to enter, lets say his name and then write it on the screen.
: How do I do that without string (since I cant use that in Standard Pascal)?
: Array? But how?
:
: program name;
: uses crt;
: var
: name : array[?] of char;
: begin
: clrscr;
: write('Please enter your name: ');
: readln(?);
: writeln('Your name is', ?);
: end.
:
: I know, kinda stupid program. Its just for understanding the basic function.
:
: Would be cool if someone could complete this for me.
: Im using TP5.5 (but I may not use the abilities of Turbo. School, you know :-( )
:
: Thanx in advance
:
: Marcus
:
Hi Marcus,
Your program should work if it looked something like this:
Program EnterName;
Uses
Crt; {Or CRT2}
VAR
Name : ARRAY[1..10] OF Char;
i : Integer;
BEGIN
i := 0;
Write('Enter your name: ');
WHILE Name[i] <> #13 DO { #13 Means 'Enter' }
BEGIN
i := i + 1;
Name[i] := Readkey;
Write(Name[i]);
END;
WriteLn;
WriteLn('Your name is: ',Name);
ReadLn;
END.
Good Luck,
Greetz,
Rodolpho.
Its almost the same I did in the meantime. I made a unit out of it. But I have one little problem.
Here is my code:
MY MAINPROGRAM:
program name;
uses crt, tstring;
begin
clrscr;
write('Please enter your name: ');
textin;
writeln;
write('Thank you ');
textout;
write(' for your cooperation.'); CUTS OF A THE ALREADY WRITTEN
readln;
end.
MY UNIT:
unit tstring;
interface
var text : packed array[1..255] of char;
i, j : integer;
procedure textin;
procedure textout;
implementation
procedure textin;
begin
i := 0;
repeat
i := i + 1;
read(text[i]);
until text[i] = chr(13);
end;
procedure textout;
begin
j := i;
i := 0;
repeat
i := i + 1;
write(text[i]);
until i = j;
end;
end.
Line 10 in my main program, starts writing at the beginning of the line again. It cuts of the previous stuff. Why?
Maybe you know how to fix that?
Greetz
Marcus
procedure textin;
var ch:char;
begin
i:=0;
repeat
i:=i+1;
ch:=readkey;
write(ch);
if ch<>#13 {ENTER} then text[i]:=ch;
until (i=10)or(ch=#13);
and b4 u run all this, do the following:
fillchar(text,sizeof(text),' ');
this puts a space in #sizeof(text) cells in the array 'text'.
it can also do strings and whatever array u like with whatever info can be in it.. first u enter the name of array/string, then how many bytes/cells to fill and last, what to fill them with.
or you can do this:
for i:=1 to 10 do text[i]:=' ';
will also work if you don't know the other one and don't want to know it yet, even tho it's rather simple.
i checked this out and the code i gave you works 4 me assuming text is your array and i is your counter there shouldn't be any problems..if so keep posting till this thing is solved
till then - achew!
//Noam