If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
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.

[RESOLVED] deprecated conversion from string const to char*

I am having an error after compiling the program with above warning. i believe i'm doing something wrong my code is as below. program terminates with seg fault

in main i'm calling sqlfunction.cpp to query mysql database.
timer loop dumps the result to the mysql database by querying sqlfunction.
program runs in the main ok even with the warnings. but it doesnt run in the timer loop and terminates with seg fault.????? please help what should i change in this

Re: deprecated conversion from string const to char*

I am having an error after compiling the program with above warning. i believe i'm doing something wrong my code is as below. program terminates with seg fault

Please use code tags when posting code. The code you posted is practically unreadable.

Second, why not go through your code with a debugger? At the very least, please find out which line is causing the issue. If it's one of those database calls or return values from these calls, then how can we help you if we don't have the database or the data that is being returned?

Re: deprecated conversion from string const to char*

Thanks Paul. sorry about the first post. Ive been mucking around with this since yesterday for 5-6 hours. if you look around the timer loop you will find the return value is just a float ("mul" check comment with //)
"Querydb" function works fine in main even though i have compile error.
but if the same function is called from the timer thread then the program crashes with seg fault.(with compiler spitting out above warning but no error)

I know the issue and it is the mysql string i'm using with the function in sqlfunction.cpp file

Code:

bool Querydb(char * query, double Myarray)

but i dont know how i define the query in Querydb so it can take strings as an input

Re: deprecated conversion from string const to char*

"Querydb" function works fine in main even though i have compile error.

If there was a compiler error, then the program would never have been created.

First, please indent your code. It still is almost impossible to read.

but if the same function is called from the timer thread then the program crashes with seg fault.(with compiler spitting out above warning but no error)

But you did not identify exactly which line is causing the problem.

I know the issue and it is the mysql string i'm using with the function in sqlfunction.cpp file

Code:

bool Querydb(char * query, double Myarray)

That is just a function prototype -- it is not the actual executable line that is invoked to cause the error. Please state which line, when you run the program, causes the crash.

Secondly, those prototypes take char*, and by convention, functions that take char* can potentially change the characters being pointed to. But if you take a look at how you're calling these functions, you're passing string-literals, and string literals cannot be modified.

Code:

extern bool Opendb(char *pc, char *user, char *pass, char *db);

If a programmer were using the API for the first time, they would see the prototype as char*, meaning whatever you pass must be passed as a modifiable buffer. The programmer would then pass a modifiable array of char:

Re: deprecated conversion from string const to char*

If a programmer were using the API for the first time, they would see the prototype as char*, meaning whatever you pass must be passed as a modifiable buffer. The programmer would then pass a modifiable array of char:
Code: