looping lines and blocks of characters
all,
I have a file that is like the following, with patterns of pipes in it:
Code:
||| || | |
| ||| | | |
|| || ||
I have to consider each row of pipe characters to be in blocks of 3 characters each (e.g. - positions 1-3, then 4-6, etc, etc...) but I have to capture all of the pipes, in sequence, like so:
positions 1-3 for lines 1-3, then positions 4-6 for lines 1-3, etc, etc...
anyone have any efficient ideas on how to get this done besides writing severely redundant control structures like loops, one after the other? That's about all I can think of here but I don't have enough extensive knowledge in VCPP to know any alternative resources that can solve the problem...
thanks.
Re: looping lines and blocks of characters
Well, what is wrong with loops?
Re: looping lines and blocks of characters
Quote:
Originally Posted by
VictorN
Well, what is wrong with loops?
well nothing. how exactly would you do this? what nestings would you use?
Re: looping lines and blocks of characters
Victor,
what I'd like to do is find a way to code in reading 3x3 matrices from these lines. does that make sense? that way I don't have to patternize this stuff by issuing a million iterations. I can't figure out that little method, that's all. need help!
Re: looping lines and blocks of characters
Quote:
Originally Posted by
ajetrumpet
I have to consider each row of pipe characters to be in blocks of 3 characters each (e.g. - positions 1-3, then 4-6, etc, etc...) but I have to capture all of the pipes, in sequence, like so:
positions 1-3 for lines 1-3, then positions 4-6 for lines 1-3, etc, etc...
Just read three lines of text at a time and generate the blocks from those lines.
Re: looping lines and blocks of characters
Hmmm, I could swear someone else just posted questions about this same assignment a little while ago ...
nested loops to streamlined code
And would you know it was from the same user? :wave:
You could scan the file each time to extract one 3 x 3 matrix. Just reset the file pointer in between. Also, if you can assume each line has the exact same number of characters (including the new line character), you could calculate the file pointer position for the start of each row for a given matrix. Granted, this is not the most efficient method, but ...