Hi,
There are a few issues with the code snippet you've posted. First, it looks like you want
c to hold the int value
32, but you can't just dereference and cast the string
"32" as an int to make that happen:
c = (int)*data;
The dereference will just give you the first character in that string, and
c will just end up storing the ascii code for that character. In general, if you need to convert a string into an integer, you need to use a function like
atoi. In this case, however, you can just use the
Ini_GetInt function to read "Number of Groups" directly into an integer.
Another problem is that
getVal will never actually output the string returned by
Ini_GetData. Your getVal function's data parameter needs to be an
unsigned char **, not just an
unsigned char *. Also, you do not need to dynamically allocate the local variable
data in
main (which incidentally is allocated as the wrong type, since it is declared as an
unsigned char *) since
Ini_GetData allocates the memory for you, but you
do need to free the string returned by
Ini_GetData.
Here is a snippet that shows how to get "Number of Groups" as well as a hypothetical string value "Some String":
void testIniRead(void)
{
unsigned char *data;
int c;
int dataSize;
Ini_GetInt(iniTextStream, "MOTOR GROUP SETTINGS", "Number of Groups", &c);
Ini_GetData(iniTextStream, "MOTOR GROUP SETTINGS", "Some String", &data, &dataSize);
/* use/copy data */
free(data);
}
You should also take a look at the sample CVIXX\samples\toolbox\ini.prj for more details on how to use the INI functions.
Hope this helps.
Mert A.
National Instruments