Thread: adding columns in output

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    37

    adding columns in output

    I originally pulled this code out of the book to experiment with auto-numeric generation
    I have later found an easier way or compromise to the programs original purpose.
    But now i am back on just advancing my performance.
    For you advanced users this script is simple.
    Is there any way i can be educated on how to add columns on the with in the example script listed
    such as current characters display at binary placements
    #1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,50#
    #1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,output,,,,,,,,,, ,,,,,,,50#
    #1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, space,,,,,,,,,,,,,,,,,,,,,50#
    #1,,,,,,,,,,,,,,,,,,,,,,, colum,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,50#
    I am not trying to confuse anyone or myself when i use the word binary just reflecting on the characters physical placement as a numeric switch of a new line tab or space if columns are not allowable.

    Code:
    #include<stdbool.h>
    #include<stdio.h>
    #include<stdlib.h>
    #include<time.h>
    
    
    
    
    
    #define NUM_SUITS 4
    #define NUM_RANKS 13
    #define NUM_RAD 9
    #define NUM_average 0
    
    int main(void)
    {
    bool in_hand[NUM_SUITS] [NUM_RANKS] [NUM_RAD] = {false};
    bool in_deck[NUM_average] = {false};
    int num_cards, rank, rad, suit, average;
    const char rank_code[] = {'2','3','4','5','6','7','8','9','t','j','q','k','a'};
    const char suit_code[] = {'c','d','h','s'};
    const char rad_code[] = {'t','m'};
    const char average_code[] = {'y'};
    
    srand((unsigned) time(NULL));
    
    printf("htttp\n");
    scanf ("%d", &num_cards);
    scanf ("%d", &rad);
    
    
    
    printf("c for compressor f forklit  g grinder a air tools:");
    while (num_cards > 0) {
    suit = rand()% NUM_SUITS;
    rank = rand()% NUM_RANKS;
    rank = rand()% NUM_RAD;
    
    if (!in_hand[suit] [rank] [rad]) {
        in_hand[suit] [rank] [rad] = true;
        num_cards--;
    printf("%c%c", rank_code[rank], suit_code[suit], rad_code[rad]);
    
    while (in_deck > 0) {
    suit = rand()% NUM_SUITS;
    
    printf("%c%c", rank_code[rank], suit_code[suit], rad_code[rad]);
    printf("average %G\n", average_code, (&num_cards));
    }
    }
    printf("\n");
    return 0;
    }
    }

  2. #2
    Registered User
    Join Date
    Dec 2012
    Posts
    307
    here is an example to help you
    Code:
    #include<stdio.h>
    int main(void)
    {
     printf("\t%5d\n\t%5d\n\t%5d\n\t%5d\n\t%5d\n\t%5d\n\t%5d\n\t", 1,12,123,1234,12345,123456,1234567);
     return 0;
    }
    experiment and go from there!
    Last edited by Crossfire; 10-26-2013 at 09:06 PM.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Uh. I'm not quite sure what you're asking (and looking at the code doesn't help, as it appears to be two programs mushed together and a fair bit of it doesn't work), but you control the format of how printf prints things by using the format string for printf. If you don't happen to have any good documentation to hand, you can type "man printf" into google (or your computer, if it's running *nix) and read up on what you can do with the format.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Output Columns form a file
    By Cdrwolfe in forum Tech Board
    Replies: 2
    Last Post: 03-22-2006, 05:12 AM
  2. Formatting output into aligned columns
    By Kheila in forum C++ Programming
    Replies: 8
    Last Post: 11-14-2005, 09:47 PM
  3. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM
  4. Output in columns
    By stryker1080 in forum C++ Programming
    Replies: 1
    Last Post: 03-06-2005, 12:58 PM
  5. Adding Columns and Rows..Help!
    By ProgrammingDlux in forum C++ Programming
    Replies: 3
    Last Post: 04-25-2002, 03:52 PM