I have project with 3 files. Common header contain function declaration for check mysql connection:
int conn_check(char **m_error);
Main file calls function and expect some message in m_error in case of error:
if (!conn_check(&m_error)==0)
{
printf("%s\n", m_error);
}
And now function in which I have problem because weak knowing of pointers:
int conn_check(char **m_error)
{
int retval = 0;
char mysqlerror[255] = {0};
MYSQL *conn;
conn = mysql_init(NULL);
if (conn)
{
if (mysql_real_connect(conn, mysql_server, mysql_user_name, mysql_password, "", (ulong)mysql_serverport, mysql_socket, 0)==NULL)
{
sprintf(mysqlerror, "%u: %s", mysql_errno(conn), mysql_error(conn));
*m_error = mysqlerror; // Problem here
retval = -1;
}
} else retval = -2;
mysql_close(conn);
return retval;
}
Question is how to properly assign string mysqlerror to char pointer m_error so error message can be printed through printf in main.