Quote:
Originally Posted by kamaralitarvez View Post
My question is how to treat a string read from a file as a structure variable ie; in ur example code consider num, i will read from file as "foo.num" and this should correspond to exact "int num" variable of ur structure.
Oh I see, so there are actually TWO input files. The only way is to compare strings; "foo.num" isn't kept anywhere in the compiled code and is just a label for the compiler's and linker's benefit. So perhaps I'd do something like:
Code:
getStrFromStringFile(str);
if (!strcmp(str,"foo.num"))
{
  foo.num=getNumFromNumFile();
}
which is tedious and error prone, because you have to make sure that the code and the structure are kept in step with each other. It would be a good idea to make sure the user is aware of any discrepancies between the input files and the data structure (a) any structure variables that haven't been assigned to and (b) any strings in the file that don't correspond to structure members. For example there is in fact no DI1WORD3 in the DIGITAL_INPUT structure.