Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

GCC does not recognize escape character '\' on multi-line input

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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 %%.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading