Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7193183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:07:05+00:00 2026-05-28T20:07:05+00:00

I have project with 3 files. Common header contain function declaration for check mysql

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:07:06+00:00Added an answer on May 28, 2026 at 8:07 pm

    char **m_error means you’re passing a pointer to a pointer. Presumably this is because the function already returns an int and you want to also have the text of the error. As it is, you’re assigning the address of a stack variable to the pointer which you can not do.

    You would need to allocate memory, assign it to the pointer, then write to it:

    *m_error = calloc(255, sizeof(char));
    snprintf(*m_error, 255, "%u: %s", mysql_errno(conn), mysql_error(conn));
    

    vasprintf() will do all of it for you:

    vasprintf(m_error, "%u: %s", mysql_errno(conn), mysql_error(conn));
    

    Note that you would then need to free() this back in the calling function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a project that references files in a Common-directory. Whenever that project is
I have a CC.NET project configured to call a common NAnt build file, which
I have a project containing files generated from a .g file (antlr 2.7.x). The
Is it possible to have multiple Qt project files in a single Eclipse project?
We have the problem that we have the open project files in our SVN
I have notices following: if I have a project with minimum files in res
We have a project with many dll files which get loaded when the application
I have a project with Crystal Reports files that doesn't seem to build correctly
I have a project consisting of two files, main.c and logoff.c. When I try
I have a project with several CSS files, each with many different settings. Every

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.