Thread: Drawing tables in C

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    2

    Drawing tables in C

    I am sorry to bother folk with such an apparently simple query but I am afraid I can't suss it out.

    I have a table of data which I need to print out but the best i can do for some sort of edging is - and |.

    is there any way i can make it look better?

    fprintf(prn_ptr,"------------------------------------------------------------------------------\n");
    fprintf(prn_ptr,"|Rec | Cust | Part | Quant | Customer |Balance |Credit |Error|\n");
    fprintf(prn_ptr,"|Type| Code | Number | | Name | |Limit |Code |\n");
    fprintf(prn_ptr,"| | | | | | | | |\n");
    fprintf(prn_ptr,"|----------------------------------------------------------------------------|\n");
    fprintf(prn_ptr,"| | | | | | | | |\n");

    stanoman

  2. #2
    Registered User JamesM's Avatar
    Join Date
    Sep 2003
    Posts
    18
    Since it looks like you're printing to file, I saved to a csv file last time I needed to do a table.

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Windows?

    If so, use the line draw characters. Run this program for their values:

    Code:
    #define VERSION " BOXCHAR  Ver 2.1        18-Jun-93        WildeWare for DOS & OS2 Family Mode"
    #include "stdio.h"
    void main(void);
    void main()
    {
        printf("%s\n\n", VERSION);
    
        printf(" %c  %c  %c    ",     218, 194, 191);
        printf(" %d %d %d          ", 218, 194, 191);
        printf(" %c  %c  %c    ",     213, 209, 184);
        printf(" %d %d %d  \n\n",     213, 209, 184);
        printf(" %c  %c  %c    ",     195, 197, 180);
        printf(" %d %d %d          ", 195, 197, 180);
        printf(" %c  %c  %c    ",     198, 216, 181);
        printf(" %d %d %d  \n\n",     198, 216, 181);
        printf(" %c  %c  %c    ",     192, 193, 217);
        printf(" %d %d %d          ", 192, 193, 217);
        printf(" %c  %c  %c    ",     212, 207, 190);
        printf(" %d %d %d  \n\n",     212, 207, 190);
        printf(" \n\n");
    
    
        printf(" %c  %c  %c    ",     214, 210, 183);
        printf(" %d %d %d          ", 214, 210, 183);
        printf(" %c  %c  %c    ",     201, 203, 187);
        printf(" %d %d %d  \n\n",     201, 203, 187);
        printf(" %c  %c  %c    ",     199, 215, 182);
        printf(" %d %d %d          ", 199, 215, 182);
        printf(" %c  %c  %c    ",     204, 206, 185);
        printf(" %d %d %d  \n\n",     204, 206, 185);
        printf(" %c  %c  %c    ",     211, 208, 189);
        printf(" %d %d %d          ", 211, 208, 189);
        printf(" %c  %c  %c    ",     200, 202, 188);
        printf(" %d %d %d  \n\n",     200, 202, 188);
        printf(" \n\n");
    
        printf("    %c  %c  ",        196, 179);
        printf(" %d %d             ", 196, 179);
        printf("    %c  %c  ",        205, 186);
        printf(" %d %d  \n\n",        205, 186);
        printf(" \n\n");
    
        printf(" %c%c%c%c%c%c%c    ", 218, 196, 196, 194, 196, 196, 191);
        printf(" %c%c%c%c%c%c%c    ", 213, 205, 205, 209, 205, 205, 184);
        printf(" %c%c%c%c%c%c%c    ", 214, 196, 196, 210, 196, 196, 183);
        printf(" %c%c%c%c%c%c%c    ", 201, 205, 205, 203, 205, 205, 187);
        printf(" \n");
        printf(" %c  %c  %c    ",   179, 179, 179);
        printf(" %c  %c  %c    ",   179, 179, 179);
        printf(" %c  %c  %c    ",   186, 186, 186);
        printf(" %c  %c  %c    ",   186, 186, 186);
        printf(" \n");
        printf(" %c%c%c%c%c%c%c    ", 195, 196, 196, 197, 196, 196, 180);
        printf(" %c%c%c%c%c%c%c    ", 198, 205, 205, 216, 205, 205, 181);
        printf(" %c%c%c%c%c%c%c    ", 199, 196, 196, 215, 196, 196, 182);
        printf(" %c%c%c%c%c%c%c    ", 204, 205, 205, 206, 205, 205, 185);
        printf(" \n");
        printf(" %c  %c  %c    ",   179, 179, 179);
        printf(" %c  %c  %c    ",   179, 179, 179);
        printf(" %c  %c  %c    ",   186, 186, 186);
        printf(" %c  %c  %c    ",   186, 186, 186);
        printf(" \n");
        printf(" %c%c%c%c%c%c%c    ", 192, 196, 196, 193, 196, 196, 217);
        printf(" %c%c%c%c%c%c%c    ", 212, 205, 205, 207, 205, 205, 190);
        printf(" %c%c%c%c%c%c%c    ", 211, 196, 196, 208, 196, 196, 189);
        printf(" %c%c%c%c%c%c%c    ", 200, 205, 205, 202, 205, 205, 188);
    }
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  4. #4
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    why did you make a prototype of void main???

    please use int main first of all.

    Second, why would you make a prototype, it seems inefficient...

    -LC
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  5. #5
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Originally posted by Lynux-Penguin
    why did you make a prototype of void main???

    please use int main first of all.

    Second, why would you make a prototype, it seems inefficient...

    -LC
    Sorry about that, but look at the date....

    I'm one that keeps mentioning the use of "void main()". I didn't read the code this time because the thing has always worked so I just posted it. It is after all code from 10 years ago..
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  6. #6
    Registered User
    Join Date
    Oct 2003
    Posts
    2
    thanks for the replies. I've not had time to try them out yet. I'll let you know how I get on when I do.

    stanoman

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing HBITMAP into CWnd, Acquired from "screenshot"
    By DeusAduro in forum Windows Programming
    Replies: 6
    Last Post: 07-02-2009, 03:41 PM
  2. C++ style tables
    By MarkZWEERS in forum C++ Programming
    Replies: 4
    Last Post: 05-18-2009, 08:41 AM
  3. Slow drawing code
    By tjpanda in forum Windows Programming
    Replies: 5
    Last Post: 05-09-2008, 05:09 PM
  4. Line Drawing Algorithm
    By Axpen in forum Game Programming
    Replies: 15
    Last Post: 08-01-2005, 06:30 PM
  5. How to do double buffing with win32 drawing?
    By Josh Kasten in forum Windows Programming
    Replies: 2
    Last Post: 03-27-2004, 12:02 AM