1

The below will raise compilation warning warning: unknown conversion type character ‘w’ in format [-Wformat=] on a new version of gcc: gcc (Debian 12.2.0-14) 12.2.0

#include <stdio.h>


int main() {
    char query[4096];
    snprintf(query, sizeof(query), "SELECT e.expression_id, e.name, e.channel, e.subsidiary_of, ds.input_channel FROM expression e "
            " JOIN shoe s ON s.shoe_id = e.shoe_id JOIN device_serial ds ON s.device_id = ds.device_id " 
            "WHERE e.name NOT LIKE '\%walker\%' ORDER BY e.channel");
    printf("%s \n", query);
    return 0;
}

It works fine on a shorter input and also on older versions of gcc. How can I make it recognize the backslash as an escape character?

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
Cheetaiean
  • 901
  • 1
  • 12
  • 26

1 Answers1

4

Just write

"WHERE e.name NOT LIKE '%%walker%%' ORDER BY e.channel"

From the C Standard (7.21.6.1 The fprintf function)

8 The conversion specifiers and their meanings are:

% A % character is written. No argument is converted. The complete conversion specification shall be %%.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335