-
March 17th, 2013, 03:38 PM
#1
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.
-
March 17th, 2013, 04:29 PM
#2
Re: looping lines and blocks of characters
Well, what is wrong with loops?
Victor Nijegorodov
-
March 17th, 2013, 04:43 PM
#3
Re: looping lines and blocks of characters
Originally Posted by VictorN
Well, what is wrong with loops?
well nothing. how exactly would you do this? what nestings would you use?
-
March 17th, 2013, 07:51 PM
#4
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!
-
March 18th, 2013, 03:08 AM
#5
Re: looping lines and blocks of characters
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.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
-
March 19th, 2013, 12:43 AM
#6
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?
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 ...
Last edited by Coder Dave; March 19th, 2013 at 12:45 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|