printf不处理%zu

时间:2017-05-29 13:36:29

标签: c gcc printf mingw-w64

printf似乎无法正确处理此程序中的%zu。在我的机器上输出

Is there anybody out there?
Size is: zu

预期输出

Is there anybody out there?
Size is: 27

它使用%u打印预期输出,但我认为它应该与z修饰符一起使用

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    FILE* text;
    errno_t ec;

    ec = fopen_s(&text, "text.txt", "r");

    if (ec) {
        fputs("Failed to read file", stderr);
        return EXIT_FAILURE;
    }

    char msg[28];
    fgets(msg, 28, text);

    puts(msg);
    printf("Size is: %zu\n", strlen(msg));

    fclose(text);
}

我正在使用gcc 6.3.0(mingw-w64)编译并启用了c11

0 个答案:

没有答案