Help with formatting

This is a discussion on Help with formatting within the C Programming forums, part of the General Programming Boards category; I'm doing a basic program where you look a players number and thier stats appear. now i could just try ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    7

    Help with formatting

    I'm doing a basic program where you look a players number and thier stats appear. now i could just try and format the thing by hand but i was wondering if thier was a way i could format something to look like this auto.
    year team g gp a pts...so fourth. im not looking for a code(but will accept one happily) but rather a pointer on what i should focus on?

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Hint: \t.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    40
    Maybe you could look at the length of each field (i.e. the information you get from the file) and then add a number of spaces based on wanting a total length for the field, i.e. something like:
    int inpLength=stringSize(input);
    int spaces=totalFieldSize-inpLength;
    printSpaces(spaces);

    The functions are ficticious, but..

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    7
    alright, i mean i got alot a time to try and figure out something simpler if there is anything. thank you

  5. #5
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Or get printf() to do it for you.

    printf("%20s", input);

    Ensures input is atleast 20 characters long, padding with spaces. See http://www.cplusplus.com/reference/c...io/printf.html

    I'd rather use tabs in this case

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dos game help
    By kwm32 in forum Game Programming
    Replies: 7
    Last Post: 03-28-2004, 05:28 PM
  2. Need a hand formatting numbers.
    By Furious_George in forum C++ Programming
    Replies: 10
    Last Post: 10-15-2003, 10:12 AM
  3. Formatting Standards
    By subdene in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 11-22-2002, 03:36 PM
  4. Need help with something small - formatting problem
    By wireless in forum C++ Programming
    Replies: 0
    Last Post: 05-28-2002, 05:52 PM
  5. Problem Formatting double numbers.
    By chaps67 in forum C++ Programming
    Replies: 1
    Last Post: 09-19-2001, 09:20 AM

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