CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2013
    Posts
    25

    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.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: looping lines and blocks of characters

    Well, what is wrong with loops?
    Victor Nijegorodov

  3. #3
    Join Date
    Mar 2013
    Posts
    25

    Re: looping lines and blocks of characters

    Quote Originally Posted by VictorN View Post
    Well, what is wrong with loops?
    well nothing. how exactly would you do this? what nestings would you use?

  4. #4
    Join Date
    Mar 2013
    Posts
    25

    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!

  5. #5
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: looping lines and blocks of characters

    Quote Originally Posted by ajetrumpet View Post
    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

  6. #6
    Join Date
    Feb 2013
    Location
    United States
    Posts
    56

    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
  •  





Click Here to Expand Forum to Full Width

Featured