user4653363
user4653363

Reputation: 11

Simple printf program doesn't work

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

Upvotes: 0

Views: 186

Answers (2)

cremno
cremno

Reputation: 4927

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]

Upvotes: 8

ChristianMurschall
ChristianMurschall

Reputation: 1711

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

You should check your character encoding.

Upvotes: 0

Related Questions