is it possible to convert a string read from file to converted into structure variabl

kamaralitarvez's Avatar, Join Date: Jan 2009
Light Poster
Hi,
i am reading data from a file which is in string format and is it possible to convert the same into variable of a nested structure and assign numerical values to it.

Reply awaited.

Regards,
Kamar.
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Yes.
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Why do you think it would not be possible ?
kamaralitarvez's Avatar, Join Date: Jan 2009
Light Poster
Quote:
Originally Posted by shabbir View Post
Why do you think it would not be possible ?

can you explain me how it can be acheived.
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Read the content of the file and then start assigning them to the object members and that would be one of them.
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
The approach I often use is to scan the string with a for loop and use a state variable which determines where we're up to in the source string, then to decode the string and assign appropriate values to appropriate members of the structure within a switch. But it depends very much on the structure of the string, if it contains, say, "a=1,b=2,c=3" and this means assign 1 to a, 2 to b and 3 to c then you don't really need much of a state machine at all. Can't really say much more than that due to the vagueness of the question.

Can you give an example string (make it a short one, less than 30 characters but containing 3-4 data items that need assigning), and structure, and what should be assigned to what, and I'll consider having a go at presenting an example of how I might do it.
kamaralitarvez's Avatar, Join Date: Jan 2009
Light Poster
Quote:
Originally Posted by xpi0t0s View Post
The approach I often use is to scan the string with a for loop and use a state variable which determines where we're up to in the source string, then to decode the string and assign appropriate values to appropriate members of the structure within a switch. But it depends very much on the structure of the string, if it contains, say, "a=1,b=2,c=3" and this means assign 1 to a, 2 to b and 3 to c then you don't really need much of a state machine at all. Can't really say much more than that due to the vagueness of the question.

Can you give an example string (make it a short one, less than 30 characters but containing 3-4 data items that need assigning), and structure, and what should be assigned to what, and I'll consider having a go at presenting an example of how I might do it.



Hi,
the string read from file will be like ACM.IODATA.DI.DI1WORD3.T4 and it has to be converted to structure variable.
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
A structure variable containing what field types?
And what will those fields contain after parsing the above string?
It's not obvious from the string, so you need to provide more information.
kamaralitarvez's Avatar, Join Date: Jan 2009
Light Poster
Quote:
Originally Posted by xpi0t0s View Post
A structure variable containing what field types?
And what will those fields contain after parsing the above string?
It's not obvious from the string, so you need to provide more information.
in ACM.IODATA.DI.DI1WORD3.T4, t4 is integer variable member of DI1WORD3 structure and DI1WORD3 is a member of DI structure and DI is a member of IODATA and IODATA is a member of ACM structure.


This is needed for aircraft simulation and these are all messages send thru 1553 bus and all are nested structures.
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
So if the string contains just "ACM.IODATA.DI.DI1WORD3.T4", how do you know what integer value to assign to ACM.IODATA.DI.DI1WORD3.T4?

Please remember I can't read your mind and I don't have the code in front of me. I can only go on what you give me in this thread, which so far is very little. So please give an example of a string that should be parsed, containing several variables (but still reasonably short), and an example of the structure it should go into and the values that should be assigned as a result.

Last time of asking, so if you don't answer the above in full detail instead of answering with such minimal answers that you don't include the basic info I need to answer then I won't bother replying again.