Problems with char conversion


I’m stuck with a problem for hours now that I cant solve on my own. I try to catch data from a MySql query and parse it into a normal char. Later on, I want to do some if statements.

The database is just one row and one column with 4 digits, I use them to control parts of my smart home.

void mysqlabfrage(){

  Serial.println("Starte MYSQL ABFRAGE");

  if (conn.connect(server_addr, 3306, user, password)) {
  row_values *row = NULL;
  long head_count = 0;
char query[] = "SELECT statuss FROM sql11215113.homecontrol";

  MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);

  // Execute the query
  // Fetch the columns and print them

  column_names *cols = cur_mem->get_columns();

  do {
    row = cur_mem->get_next_row();
    if (row != NULL) {
      for (int f = 0; f < 4; f++) {

        testasd[f] = (row->values[f]);


  } while (row != NULL);

  delete cur_mem;



For testasd[f] = (row->values[f]); to work I need to declare testasd as char*.

The problem is the following:

 for (int f = 0; f < 4; f++) {

        testasd[f] = (row->values[f]);


Im able to see the data in my serial output (for example ‘ABCD’)but Im not able to put them into a normal char to then check (for example) if testasd[0] == ‘A’ .I get an error indicating an invalid operating with a char*.
Any ideas?

All I want to do is to check if testasd[0] == ‘A’ , testasd[1] == ‘B’ and so on.

Hi, Your biggest problem is in assuming you know what the problem is and only posting part of the code.

You don't know what the problem is, so don't guess... describe the problem and post all the code.

You might be lucky... my crystal ball might be working....


what you need is:


but I could be wrong 'cos you didn't give me enough info.

Yours, TonyWilk

Also posted on Stack Exchange

You are just copying the pointers, the library will probably change the memory they point to. Look up strcpy.

That being said, you are comparing a pointer (char*) to a char. That doesn't make any sense of course, and the compiler complains. Keep in mind that a "string" is actually a char*, a pointer to an array of characters. testasd is a pointer to an array of pointers to char pointers (char*). If you index (or dereference) it once, you get a pointer to a char array (char), if you index it twice, you get a single character (char).

Take a look at the strcmp function, don't compare each individual character yourself if you don't have to.

All that aside, it is beyond me why you would do all of that on the microcontroller. The fact that you are using a database indicates that you have a server that's more than capable enough to run PHP scripts (or whatever language you prefer) that can do the heavy lifting. It can handle all SQL queries, the tests you're trying to do, and send the result to the microcontroller in an easily parsable format. On top of that, it means you can close your database server for external connections (for safety).