Displaying ascii boxes

This is a discussion on Displaying ascii boxes within the C Programming forums, part of the General Programming Boards category; hey ,so i have a function which draws a box on the screen every time i call it. the box ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    84

    Displaying ascii boxes

    hey ,so i have a function which draws a box on the screen every time i call it.
    the box looks somthing like this...

    Code:
    printf("_____________\n");
    printf("|                      |\n");
    printf("|                      |\n");
    printf("|                      |\n");
    printf("|                      |\n");
    printf("|                      |\n");
    printf("|                      |\n");
    printf("|                      |\n");
    printf("|                      |\n");
    printf("|                      |\n");
    printf("|___________|\n");
    printf("\n");
    now the thing is..i want to display the boxes in a single row..but every time i call the function it draws the boxes vertically because of the \n's.

    How do i display the boxes in a single row ?

  2. #2
    Banned
    Join Date
    Dec 2008
    Location
    Maputo, Mozambique
    Posts
    82
    Da way I do it iz to jus make da boxes in a string den print da string.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    84
    what about the newlines ?

  4. #4
    Banned
    Join Date
    Dec 2008
    Location
    Maputo, Mozambique
    Posts
    82
    U put da newlines when u actually print. But in memory keep da lines as just lines. Like psudo boxes, get it?

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    84
    kind of!..so u mean..if i put them in strings..then i could do something like

    print stringa1 stringb1 stringc1\n
    print stringa2 stringb2 stringc2\n ?

    ??

  6. #6
    Banned
    Join Date
    Dec 2008
    Location
    Maputo, Mozambique
    Posts
    82
    maybe like:

    Code:
    #define WIDTH 45
    #define HEIGHT 12
    
    char screen[WIDTH * HEIGHT];
    
    void set_screen(char n, int x, int y)
    {
      screen[x + y * WIDTH] = n;
    }
    
    void print_screen(void)
    {
      char *line = screen, end = screen + (WIDTH * HEIGHT);
    
      while(line < end)
      {
        printf("&#37;.*s\n", WIDTH, line);
        line += WIDTH;
      }
    }
    Duz dat help ne?

  7. #7
    Banned
    Join Date
    Dec 2008
    Location
    Maputo, Mozambique
    Posts
    82
    You would do stuff like set_screen('_', x, y) in for loops to make the tops of da boxes. Jus like a gotoxy() in DOS, but dis way you can make da whole screen at once, den print da buffer to da screen all at once. Make more cents?

  8. #8
    Registered User
    Join Date
    Oct 2008
    Posts
    84
    yea!..i what you mean!..but im trying to make playing cards...! i think i can figure it out!..thanks!

  9. #9
    Banned
    Join Date
    Dec 2008
    Location
    Maputo, Mozambique
    Posts
    82
    Ok cool. If u not get it gud, den jus say something. I can xpand on da code 4 u.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Displaying Extended ASCII
    By JMJ_coder in forum C Programming
    Replies: 2
    Last Post: 10-07-2008, 08:35 AM
  2. Replies: 11
    Last Post: 03-24-2006, 10:26 AM
  3. Office access in C/C++ NOT VC++!! :)
    By skawky in forum C++ Programming
    Replies: 1
    Last Post: 05-26-2005, 01:43 PM
  4. ascii characters video displaying on tv screen
    By deian in forum C Programming
    Replies: 6
    Last Post: 10-12-2004, 09:46 PM
  5. Checking ascii values of char input
    By yank in forum C Programming
    Replies: 2
    Last Post: 04-29-2003, 07:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21