How do I calculate the number of spaces...

This is a discussion on How do I calculate the number of spaces... within the C++ Programming forums, part of the General Programming Boards category; How do I calculate the current number of spaces between two columns of data in a line of a file, ...

  1. #1
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827

    Question How do I calculate the number of spaces...

    How do I calculate the current number of spaces between two columns of data in a line of a file, such so that I can determine how many additional spaces it will take to bring the second column to position 22 (0-based), so that I can change the line to put the correct number of spaces between the two columns of data?

    I already have the position of the last non-spc-char of the first column, and also the position of the first non-spc-char of the second column. Do I just subtract the former from the latter? That would get the number of existing spaces, but then what? How do I figure out how many additional spaces I need to bring the second column of data to position 22?
    Last edited by Programmer_P; 04-03-2011 at 01:02 PM.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,170
    You could try using I/O manipulators to pad. std::setw and std::fill, I believe.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,261
    Surely you must know the string length of the data from each column. Subtract that from the desired string length and append that number of spaces. I can't see where any difficulty youre having might be. Code might help.
    Last edited by iMalc; 04-04-2011 at 12:39 AM.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL DC Buffer Renders slow
    By Lane the Great in forum Game Programming
    Replies: 10
    Last Post: 01-07-2011, 06:52 PM
  2. Replies: 11
    Last Post: 10-07-2008, 06:19 PM
  3. Random number + guessing game trouble
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-08-2007, 03:33 AM
  4. how to calculate billion number
    By mrmamon in forum C++ Programming
    Replies: 9
    Last Post: 10-16-2005, 06:34 AM
  5. calculate the ln of a number?
    By willc0de4food in forum C Programming
    Replies: 9
    Last Post: 04-04-2005, 04:39 PM

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