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

    reading character symbols on lines of text, position by position

    hello all,

    I noticed that this forum has many viewers and I try to post on forums that have that. This is a duplicated post from StackOverFlow.com simply because over there it seems they require extreme specificity on issues. Here's what I need help with:

    ===============================================

    Hello All,

    What I have to do is write a small program in C++ to parse the symbols that are used on 5 different lines of text in each position until position 30 is reached on each line. The goal of the parsing program is to interpret the symbols (characters), if there are any per each position, on the 5 lines of text in order to output the actual data that the group of symbols represents.

    My question for is this: Is there anything special from a C++ environment that should go in to something like this outside of using standard stuff like the math associated with the search algorithm that has to happen here? The symbols are located in a file, so I know I have to include "iostream" and a few other headers. But outside of header inclusions and the code necessary to iterate and streamline the search and interpretation process, am I missing anything special that I couldn't otherwise find through simple google searches?

    thanks guys.

    ===============================================

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: reading character symbols on lines of text, position by position

    Your question is extremely vague and doesn't seem to make a whole lot of sense.

    you talk about parsing 5 lines of text.
    Then you ask about math, and searching. Neither of has anything to do with parsing text.

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

    Re: reading character symbols on lines of text, position by position

    Quote Originally Posted by ajetrumpet View Post
    What I have to do is write a small program in C++ to parse the symbols that are used on 5 different lines of text in each position until position 30 is reached on each line.
    Well, the very simple way to begin would be:
    1. read each line in some character buffer
    2. truncate buffer to contain max 30 symbols
    3. parse the contents of the buffers according to your needs
    Victor Nijegorodov

  4. #4
    Join Date
    Mar 2013
    Posts
    25

    Re: reading character symbols on lines of text, position by position

    Quote Originally Posted by OReubens View Post
    Your question is extremely vague and doesn't seem to make a whole lot of sense.

    you talk about parsing 5 lines of text.
    Then you ask about math, and searching. Neither of has anything to do with parsing text.
    here's an example of 2 lines of text you guys:

    | + = _ | _ |
    | } ; | _ | _
    | | | _ | _ |

    so say for instance I wanted to read these 3 lines of text and use a search algorithm to determine which column of positions results in a strait line?? It would be column 1 because the chars in that columns are all pipes.

    That's a good example of what I'm getting at. I'm sure I can figure out the mathematics behind it but I was looking for anything special I might need from C++ outside of the steps that Ozug has given. That's about what I was thinking.

    thanks.

  5. #5
    Join Date
    Mar 2013
    Posts
    25

    Re: reading character symbols on lines of text, position by position

    I'm sorry, I mean outside of what *VictorN* says.

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: reading character symbols on lines of text, position by position

    If you only want to read 5 lines of text from a file with each line limited to 30 chars, I would consider using an array of string

    Code:
    #include <string>
    using namespace std;
    string text[5];
    then each of the 5 lines from the file would be an element of the string array.

    Another possible is to use a 2-dimensional char array as each of the max 5 lines read is limited to 30 chars.

    Code:
    char text[5][30];
    this would require a little more care creating from the file to make sure buffer-overflow didn't occur but may be the easiest to work with. This all depends really upon what you want to do with the data once it is has been obtained and whether working with string or char arrays is more suited for what you want to accomplish.

    Is this a homework assignment? If you post some code we'll provide advice if asked. If you do post code, please use code tags (Go Advanced, hightlight code, click '#').
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  7. #7
    Join Date
    Mar 2013
    Posts
    25

    Re: reading character symbols on lines of text, position by position

    kaud,

    No its not homework. I'll choose the way to do it here soon. Basically this is what it is:

    ***I'm reading character symbols from lines of text that are interpreted as code for another value in actuality. So basically what I'm doing here is reading the symbolism patterns that occur throughout 5 lines of text and using some sort of algorithmic coding to search for the appropriate actual answer that the 5 lines of symbols represent.

    The answer pool is external. I don't want to hard code answers in to the project obviously, but I can deal with that part on my own.

    Does that make more sense? I know this was vague, but it unfortunately has to be to some extent.

    thanks for your input. it *is* helpful!

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