The variable cn
is passed by value to the function myconnect
, i.e. the function receives a copy and assign a value to that copy. This has no effect in main
.
To have a effect, you have to passed it by reference. In C, that means you have to pass a pointer to the variable, which is itself a pointer:
int myconnect(OCI_Connection** cn)
{
if (!OCI_Initialize(err_handler, NULL, OCI_ENV_DEFAULT))
return 0;
*cn = OCI_ConnectionCreate(DB, DBUSER, DBPASS, OCI_SESSION_DEFAULT);
if (*cn == NULL)
return 0;
return 1;
}
int main()
{
OCI_Connection* cn;
if (myconnect(&cn) == 0)
{
dbErr =1;
}
}