Click here to Skip to main content
15,899,475 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I read 3 lines from a text file. Then I would convert them into several sub-string
What do I do.
Should
C++
' '
ignore it.
input:
C++
int  s ;
int f;
d  = 12  ;
c=10;

output:
C++
string a={int,s,;};
string b={int,f,;};
string c={d,=,12,;};
string f={c,=,10,;};
Posted
Updated 5-Dec-13 22:08pm
v2

Hi It is very simple.First of all each line should seprate with Enter key.Then parse lines until Keys.Enter and add your string to line.
Yours Farhad.
 
Share this answer
 
If your parser doesn't have to be too general (i.e. the examples there are all the things it has to cope with) and I didn't fancy messing about with a parser generator I'd do something like:

while( lines_to_read )
    read a line
    remove the terminating semi-colon

    has the line got an '=' in it?
        yes: it's an assignment
            split line into two at the '=' character
        no: it's a declaration
            split line into two at the first white space character

    trim whitespace from each substring
    form output string
 
Share this answer
 
You have to write a (very simple) lexer. Google is your friend[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900