Monday, December 20, 2010

Print % using printf in C

Problem:

How can you print % using the printf function? (Remember % is used as a format specifier!!!)
Very Simple, following cases are examples

#include <stdio.h>

int main()
{
    printf("\%\n"); // warning: unknown conversion type character 0xa in format - but prints
    printf("%%\n"); // correct statement
    printf("%\n");  // warning: unknown conversion type character 0xa in format
}

Cheers!!
Jack

1 comment:

Unknown said...

you can do this, too :

printf ("%c", '%');