Results 1 to 10 of 12

Thread: Ascii help / column width - new to this.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Here's how I would do it:
    Code:
    program ASCIITABLE;
    
    const
        ColumnCount = 6;
        ColumnWidth = 8;
    
    var i: longint;
        ch: Char;
    
    begin
       writeln ('A to Z in ASCII');
       
       for i := 0 to 127 do
       begin
          write(chr(i):ColumnWidth);
          
          // Each column start at index 0, and ends at ColumnCount-1
          if (((i+1) mod ColumnCount) = 0) then
             Writeln;
       end;
       
       Writeln;
       writeln('Press any key to continue' ,ch);
       read(ch);
    end.
    The magic happens in a special syntax for the write/writeln function

    If you call Write('a':4); then it'll write " a". Write(1:5); will produce " 1". This is some bad syntactic sugar that's always existed in Pascal
    Last edited by JSoftware; 20-02-2011 at 10:14 PM.
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •