M
mahurshi
i have a simple question guys
i have to read a file that looks more or less like this
AND 1 2 3
OR 2 3 4
INV 5 2
BUF 7 1
AND 1 2
INPUT 1 2 3 4 -1
OUTPUT 5 7 -1
(i just made up some random numbers but i guess that gives an idea of
the input file format)
onw what i want to do is read this input into a structure (string name,
int array of inputs, int one output .. the value of these ints being
the values next to the logic gate)
so for example
name = AND, inputs[0] = 1, input[1] = 2, output = 3
my question is ... how do i parse this file ? (i can do the rest
myself)
i know how to read the whole line using getline .. but it is making
things too complicated for me as the input has both characters and
integers and sometimes the number of integers is varying (e.g. INV is
followed by only 2 numbers).. and I have to somehow split these fields.
i can write this entire stuff in perl in about 3 or so lines (using =~
pattern matching) but i'd really appreciate it if someone can give me
an idea on how i can parse this file easily.
thanks
i have to read a file that looks more or less like this
AND 1 2 3
OR 2 3 4
INV 5 2
BUF 7 1
AND 1 2
INPUT 1 2 3 4 -1
OUTPUT 5 7 -1
(i just made up some random numbers but i guess that gives an idea of
the input file format)
onw what i want to do is read this input into a structure (string name,
int array of inputs, int one output .. the value of these ints being
the values next to the logic gate)
so for example
name = AND, inputs[0] = 1, input[1] = 2, output = 3
my question is ... how do i parse this file ? (i can do the rest
myself)
i know how to read the whole line using getline .. but it is making
things too complicated for me as the input has both characters and
integers and sometimes the number of integers is varying (e.g. INV is
followed by only 2 numbers).. and I have to somehow split these fields.
i can write this entire stuff in perl in about 3 or so lines (using =~
pattern matching) but i'd really appreciate it if someone can give me
an idea on how i can parse this file easily.
thanks