Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   is it possible to convert a string read from file to converted into structure variabl (http://www.go4expert.com/forums/convert-string-read-file-converted-t15987/)

kamaralitarvez 29Jan2009 15:31

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.

xpi0t0s 29Jan2009 19:10

Re: is it possible to convert a string read from file to converted into structure var
 
Yes.

shabbir 29Jan2009 20:53

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 ?

kamaralitarvez 30Jan2009 15:02

Re: is it possible to convert a string read from file to converted into structure var
 
Quote:

Originally Posted by shabbir (Post 42172)
Why do you think it would not be possible ?


can you explain me how it can be acheived.

shabbir 30Jan2009 15:18

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.

xpi0t0s 30Jan2009 21:53

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.

kamaralitarvez 2Feb2009 11:35

Re: is it possible to convert a string read from file to converted into structure var
 
Quote:

Originally Posted by xpi0t0s (Post 42220)
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 2Feb2009 12:18

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.

kamaralitarvez 2Feb2009 13:55

Re: is it possible to convert a string read from file to converted into structure var
 
Quote:

Originally Posted by xpi0t0s (Post 42299)
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 2Feb2009 16:12

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 05:59.