I am using mysql queries in c to insert data in the databases plus am using also string variables to insert data into the databases.
Am getting the error
:::format not a string literal and no format arguments [-Wformat-security]
void add_data_to_the_table(MYSQL * connection){
char schlName[200]={};
printf("Enter the school name \n");
scanf("%s",schlName);
char query_string[] = { "INSERT INTO schools(schoolName) VALUES(%s)" };
sprintf(schlName, query_string);
if (mysql_query(connection,buf))
{
validate(connection);
}
}
我原本希望将字符串插入数据库的表学校中,但是它给我的错误格式不是字符串文字,也没有格式参数[-Wformat-security]
对于初学者,此数组的初始化
char schlName[200]={};
在C中不正确。花括号中的初始化程序列表可能不为空。改写
char schlName[200]={ '\0' };
在sprintf的调用中,参数的顺序无效。看来您的意思是
sprintf( query_string, schlName );
代替
sprintf(schlName, query_string);
请注意此呼叫
scanf("%s",schlName);
不安全。使用fgets
代替scanf
。