Thread: Formatting blocks of text in C

  1. #1
    Registered User
    Join Date
    Apr 2019
    Posts
    2

    Formatting blocks of text in C

    Hi, I am a beginner to C and perhaps I haven't read far enough in the book I'm studying. I would appreciate suggestions about how to write something like this on the screen after programming it. This is what I'm trying to do:

    (Input text): Econ

    [Output looks like this]
    EEEE
    E
    EEEE cccc ooo nnnn
    E cc o o n n
    EEEE cccc ooo n n

    I am not so concerned at this point about typing an 'E' and return the large E (although that would be the eventual objective), but I'm curious about how to make the letters read left to right, rather than cascading downwards. For now I have a check mark and I can make the program print it between one and twenty times inclusive, but I don't know how to make that print left to right, rather than interating check marks on top of one another.

    Hopefully this explains the objective well and it's just for fun, although I eventually want to be skilled enough to be considered for employment or write apps (perhaps in C++ or whatever language is best suited for that).

    Thanks in advance for any ideas!

  2. #2
    Registered User
    Join Date
    Apr 2019
    Posts
    2
    By the way the post did not carry over the spaces in my example - should read 'E c o n' with the large letters comprised of the original letter (i.e. letter 'E' forming a large E on the screen).

  3. #3
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Quote Originally Posted by econdude View Post
    By the way the post did not carry over the spaces in my example - should read 'E c o n' with the large letters comprised of the original letter (i.e. letter 'E' forming a large E on the screen).
    Usualy text are presented with variable-width fonts. If you want to use monospaced fonts you can select the text and use "Courier New" font or between [ code ] and [ /code ] (without spaces after [ and before ]), as in:
    Code:
    EEEE
    E
    EE    ccc  oo  nnn
    E    c    o  o n  n
    EEEE  ccc  oo  n  n

    Last edited by flp1969; 04-25-2019 at 11:42 AM.

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    You can use code tags if you want to preserve the spacing.
    Devoted my life to programming...

  5. #5
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    About the original post, I would think of it in terms of "pixels"... I'd use a buffer, in which I would "print" the enlarged letters, which would then be printed unto the screen.
    Devoted my life to programming...

  6. #6
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Answering your question, you could use a big table to translate a char to various chars... One way to do it is using bit strings:

    Code:
    // table for 8x8 ASCII chars from ' ' to '~'.
    char font[96][8] = {
      { 0 },  // ' ' = all zeroes.
      { 0x18, 0x18, 0x18, 0x18, 0, 0x18, 0x18, 0 }, // '!' = ...**...
                                                    //       ...**...
                                                    //       ...**...
                                                    //       ...**...
                                                    //       ........
                                                    //       ...**...
                                                    //       ...**...
                                                    //       ........
    
      { 0x28, 0x28, 0x28, 0, 0, 0, 0, 0 }, // '"' = ..*.*...
                                           //       ..*.*...
                                           //       ..*.*...
                                           //       ........
                                           //       ........
                                           //       ........
                                           //       ........
                                           //       ........
      ...
      ... // all the other "chars" goes here!
    };
    Then, for every char you want to "print" you can:
    Code:
    int i, j;
    char *p = font[ch-' '];  // ch must be between ' ' and '~' only.
    
    for ( i = 0; i < 8; i++, p++ )
      for ( j = 0; j < 8; j++ )
        putchar( ( *p & ( 1 << ( 7 - j ) ) ) ? ch : ' ' );
    Of course, the code is a little bit more complex than this if you want to print multiple "characters"...
    Last edited by flp1969; 04-25-2019 at 12:03 PM.

  7. #7
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    If you want to use C++ in your job, I suggest that you learn C++ and not C.
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with formatting text
    By C89 in forum C Programming
    Replies: 10
    Last Post: 03-15-2012, 11:54 PM
  2. Help formatting text in c
    By anonymoususer in forum C Programming
    Replies: 3
    Last Post: 11-06-2011, 02:30 PM
  3. Console app: Making pretty text blocks
    By unit335 in forum C++ Programming
    Replies: 6
    Last Post: 05-31-2009, 07:22 PM
  4. need help with formatting text
    By Flikm in forum C++ Programming
    Replies: 1
    Last Post: 09-06-2001, 07:52 PM

Tags for this Thread