Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4095
Number of posts: 14004

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Array Help Posted by stevengreen22 on 22 Feb 2011 at 7:51 AM
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
Report
Re: Array Help Posted by quikcarl on 22 Feb 2011 at 12:47 PM
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.

       write (unprint[i]:columnwidth);




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.