How do you show "% 5d" in C?

How do you show the string "% 5d" in C? I tried putting a backslash before the percentage, but it won’t print (and gave warnings). I tried Googling, but to no avail. I think this is too broad for me to find a specific answer.

#include <stdio.h>

int main(void)
{
    int test = 40;
    printf("\%5.1d %5.1d", test); //this is the one
    printf("%5.1d", test);
    return 0;
}

Any help?

+3
source share
4 answers

To print %try printf("%%");

It works

printf("%%5.1d %5.1d", test);
+10
source

Use double% - printf("%%5d").

+2
source

( ) fputs() :

#include <stdio.h>

int main(void)
{
    int test = 40;
    fputs("%5d ", stdout);
    printf("%5.1d\n", test);
    return 0;
}

, ; , . , fputs(), puts(), puts() , .

, double- % printf() scanf(), .

+2

printf("%s", "%5d"):) , , , , , .

+2

Source: https://habr.com/ru/post/1787252/


All Articles