Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Array Help

stevengreen22stevengreen22 Posts: 4Member
Hi guys,

I'm close to reaching for the hammer and hopi9ng someone here can point out an obvious error I've made.
New to pascal and so on so at times I'm shooting in the dark but...

I need the ASCII characters to display in a table format. the chars 0 to 32 are throwing the table out of alignment which is frustrating...very...and my knowledge is so that I can't get aroudn the problem.

Someone in another post gave me the idea for using an array, i wanted to use a loop so that for these numbers the "name" of the key would be used instead of the printable char.

But...I cannot get it to read / write those lines, it simply misses them out and i don't knwo why.

Can anyone point me in the right direction? I'm sure it's something stupid but can't see it.

code =

rogram ASCIITABLE(output);

uses crt;

const columncount = 8; {8 columns as 128 is div perfectly by 8}
columnwidth = 3; {unprintables need 3 spaces, neater output}
Title:string = (' ASCII TABLE ');


unprint: array [0..32] of string =(
{string as below are 'string' variable}
'NUL','SOH','STX','ETX','EOT','ENQ',
'ACK','BEL','BS ','HT ','LF ','VT ',
'FF ','CR ','SO ','SI ','DLE','DC1',
'DC2','DC3','DC4','NAK','SYN','ETB',
'CAN','EM ','SUB','ESC','FS ','GS ',
'RS ','US ','SP ');


var j,i: integer;
ch: Char;
idx: byte;

begin {main program}
ClrScr;
writeln (Title);
writeln;

for i := 0 to 32 do
begin
read(unprint[i]);
write (chr(i):columnwidth);
write (' ',i:4);
if (((i+1) mod columncount) = 0) then
writeln;
end; }

for i:= 33 to 127 do
begin
write (chr(i):columnwidth);
write (' ',i:4);
if (((i+1) mod Columncount) = 0) then
writeln;
end;


{ writeln (' '); }
writeln;
writeln;
writeln ('Press any key to continue' ,ch);

read (ch);
end.


Jay...Stop thieving my code :D

Comments

  • quikcarlquikcarl Posts: 59Member
    You've got the right idea but slightly overdoing it.

    : read(unprint[i]);
    : write (chr(i):columnwidth);

    Cut out the read and change the write.

    [code] write (unprint[i]:columnwidth);
    [/code]
Sign In or Register to comment.