If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below. ** If you are logged in, most ads will not be displayed. **

When declaring UserData data; the variable data will store an address and not a value.

The data variable is declared locally in the main funtion. Normally the local variables are not initialized unless you do it explicitly. In this case, data variable is storing an unknow address.

When you use data->bndry = bndry; without allocate a valid address to data you are saying the following: "Go to the unknow address and there copy the char*. This is impossible, because the address is not valid.

In your second try you did strcpy (data.bndry, bndry); In this statement you are trying to use data as a variable that stores a struct but remember that you created the data var as a pointer. Pointer stores address =)

With that in mind, search for malloc function and the implementation of strcpy to really understand how the correct attribution is done

When declaring UserData data; the variable data will store an address and not a value.

The data variable is declared locally in the main funtion. Normally the local variables are not initialized unless you do it explicitly. In this case, data variable is storing an unknow address.

When you use data->bndry = bndry; without allocate a valid address to data you are saying the following: "Go to the unknow address and there copy the char*. This is impossible, because the address is not valid.

In your second try you did strcpy (data.bndry, bndry); In this statement you are trying to use data as a variable that stores a struct but remember that you created the data var as a pointer. Pointer stores address =)

With that in mind, search for malloc function and the implementation of strcpy to really understand how the correct attribution is done

After that come here with more doubts !!!!

Best Regards

Thanks for great reply. I added data = (UserData) malloc(sizeof *data); before the assignments, and used strcpy (data->bndry, bndry);. Works!