![]() |
is it possible to convert a string read from file to converted into structure variabl
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. |
Re: is it possible to convert a string read from file to converted into structure var
Yes.
|
Re: is it possible to convert a string read from file to converted into structure var
Why do you think it would not be possible ?
|
Re: is it possible to convert a string read from file to converted into structure var
Quote:
can you explain me how it can be acheived. |
Re: is it possible to convert a string read from file to converted into structure var
Read the content of the file and then start assigning them to the object members and that would be one of them.
|
Re: is it possible to convert a string read from file to converted into structure var
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. |
Re: is it possible to convert a string read from file to converted into structure var
Quote:
Hi, the string read from file will be like ACM.IODATA.DI.DI1WORD3.T4 and it has to be converted to structure variable. |
Re: is it possible to convert a string read from file to converted into structure var
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. |
Re: is it possible to convert a string read from file to converted into structure var
Quote:
This is needed for aircraft simulation and these are all messages send thru 1553 bus and all are nested structures. |
Re: is it possible to convert a string read from file to converted into structure var
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. |
| All times are GMT +5.5. The time now is 09:23. |