0

I would like to change the values in my char * to the int and double that are declared so I can change them without touching char *sql. (on ubuntu using C)

How can i do this?

code:

int sensor_id = 10;

double temp = 22.22;

char *sql = "INSERT INTO test_table(sensor_id, sensor_value) VALUES(10, 22.22)";
1

1 Answer 1

2

Try this (dirty, no error checking, buffer overflow may occur):

const char *sqlformat = 
            "INSERT INTO test_table(sensor_id, sensor_value) VALUES(%d, %f)";

char sql[200];
sprintf(sql, sensor_id, temp);

Now you have what you want in the sql buffer.

This is very basic C stuff, I suggest you to learn C.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.