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.
is it possible to convert a string read from file to converted into structure variabl
|
Light Poster
|
|
| 29Jan2009,15:31 | #1 |
|
Mentor
|
![]() |
| 29Jan2009,19:10 | #2 |
|
Yes.
|
|
Go4Expert Founder
|
![]() |
| 29Jan2009,20:53 | #3 |
|
Why do you think it would not be possible ?
|
|
Light Poster
|
|
| 30Jan2009,15:02 | #4 |
|
Go4Expert Founder
|
![]() |
| 30Jan2009,15:18 | #5 |
|
Read the content of the file and then start assigning them to the object members and that would be one of them.
|
|
Mentor
|
![]() |
| 30Jan2009,21:53 | #6 |
|
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. |
|
Light Poster
|
|
| 2Feb2009,11:35 | #7 |
|
Quote:
Originally Posted by xpi0t0s Hi, the string read from file will be like ACM.IODATA.DI.DI1WORD3.T4 and it has to be converted to structure variable. |
|
Mentor
|
![]() |
| 2Feb2009,12:18 | #8 |
|
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. |
|
Light Poster
|
|
| 2Feb2009,13:55 | #9 |
|
Quote:
Originally Posted by xpi0t0s This is needed for aircraft simulation and these are all messages send thru 1553 bus and all are nested structures. |
|
Mentor
|
![]() |
| 2Feb2009,16:12 | #10 |
|
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. |



