I use the structure that I pass to the function (I test the sqlite database). When all the variables in the structure were of type char* there were no problems, but when I started changing the types, the program started to crash when writing to the database.
struct Report{ int time; char *recipe_operator; int fraction_1; int fraction_2; int fraction_3; int fraction_4; int fraction_5; int fraction_6; float bitumen; int cellulose_1; int cellulose_2; int dust; int mixing_time; int temperature; int temperature_bitumen; }; write to DB:
int insertData(char* databaseName, char* tableName, struct Report *strReport){ dbOpenResult = openDatabase(databaseName); char *sql = sqlite3_mprintf( "INSERT INTO '%q' " "('%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q') " "VALUES (" "'%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q'" ",'%q');" , tableName , SCHEME_ID , SCHEME_TIME , SCHEME_RECIPE_OPERATOR , SCHEME_FRACTION_1 , SCHEME_FRACTION_2 , SCHEME_FRACTION_3 , SCHEME_FRACTION_4 , SCHEME_FRACTION_5 , SCHEME_FRACTION_6 , SCHEME_BITUMEN , SCHEME_CELLULOSE_1 , SCHEME_CELLULOSE_2 , DUST , MIXING_TIME , TEMPERATURE , TEMPERATURE_BITUMEN , strReport->time , strReport->recipe_operator , strReport->fraction_1 , strReport->fraction_2 , strReport->fraction_3 , strReport->fraction_4 , strReport->fraction_5 , strReport->fraction_6 , strReport->bitumen , strReport->cellulose_1 , strReport->cellulose_2 , strReport->dust , strReport->mixing_time , strReport->temperature , strReport->temperature_bitumen); rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg); if (rc != SQLITE_OK){ fprintf(stderr, "SQL error: %s\n", zErrMsg); sqlite3_free(zErrMsg); }else{ fprintf(stdout, "Record created successfully\n"); } sqlite3_close(db); return 0; } I pass this structure during the execution of the program:
//for test struct Report *reportStruct; reportStruct->time = 12213233; reportStruct->recipe_operator = "OPERATOR_1"; reportStruct->fraction_1 = 100; reportStruct->fraction_2 = 20; reportStruct->fraction_3 = 32; reportStruct->fraction_4 = 34; reportStruct->fraction_5 = 54; reportStruct->fraction_6 = 64; reportStruct->bitumen = 29,4; reportStruct->cellulose_1 = 0; reportStruct->cellulose_2 = 0; reportStruct->dust = 0; reportStruct->mixing_time = 30; reportStruct->temperature = 26; reportStruct->temperature_bitumen = 153; // insertData(DB_NAME, TABLE_NAME, reportStruct);