0

This program doesn't work and I don't know why.

#include <stdio.h>

int main()
{
    printf("%а", 20.0);
}

I am compiling in C99. Expected output is 0x1.4p+4

4
  • 4
    please define doesn't work. Hint: use %f Commented Mar 10, 2015 at 10:09
  • It just prints %a. Please, I want hexadecimal output. Commented Mar 10, 2015 at 10:12
  • 3
    Are you compiling in C99 mode? The %a formatting specifier is new in C99. It prints the floating-point number in hexadecimal form. Commented Mar 10, 2015 at 10:12
  • 1
    You should probably post your compiler version and how you do the compilation.
    – user694733
    Commented Mar 10, 2015 at 10:21

2 Answers 2

8

The а is CYRILLIC SMALL LETTER A (U+0430), but you have to use LATIN SMALL LETTER A (U+0061): a.

If you're using a compiler that is able to check format strings like Clang or GCC, then compile with (at least) -Wall which includes -Wformat (GCC Warning documentation)

5 : warning: unknown conversion type character 0xffffffd0 in format [-Wformat]
5 : warning: too many arguments for format [-Wformat-extra-args]
1
  • I found it helpful to go all the way and have a test program that yells at me whenever there is any non-ASCII-7 character in my sources, using proper escape sequences whenever I need non-ASCII-7. Stuff like this can drive you insane.
    – DevSolar
    Commented Mar 10, 2015 at 10:37
0

Its really wired. When I copypaste your code it turns into printf("%?", 20.0);

You should check your character encoding.

Not the answer you're looking for? Browse other questions tagged or ask your own question.