Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C:将%No作为printf的格式说明符进行解释_C_Printf_Mingw - Fatal编程技术网

C:将%No作为printf的格式说明符进行解释

C:将%No作为printf的格式说明符进行解释,c,printf,mingw,C,Printf,Mingw,以下代码段的输出(将%No视为字符串) 在linux机器上是:a%No 23 在windows计算机上时为:a 101 23 windows计算机上的输出随着%No说明符的不同参数而不断变化。关于此说明符的任何解释都将非常有用。 提前谢谢 在我的windows计算机上输出gcc-v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=c:/program files (x86)/codeblocks/mingw/bin/../li

以下代码段的输出(将
%No
视为字符串)

在linux机器上是:
a%No 23

在windows计算机上时为:
a 101 23

windows计算机上的输出随着
%No
说明符的不同参数而不断变化。关于此说明符的任何解释都将非常有用。 提前谢谢


在我的windows计算机上输出
gcc-v

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/program files (x86)/codeblocks/mingw/bin/../libexec/gcc/mingw32/4.7.1/lto-wrapper.exe
Target: mingw32
Configured with: ../../src/gcc-4.7.1/configure --build=mingw32 --enable-languages=c,c++,ada,fortran,objc,obj-c++ --enable-threads=win32 --enable-libgo
mp --enable-lto --enable-fully-dynamic-string --enable-libstdcxx-debug --enable-version-specific-runtime-libs --with-gnu-ld --disable-nls --disable-wi
n32-registry --disable-symvers --disable-build-poststage1-with-cxx --disable-werror --prefix=/mingw32tdm --with-local-prefix=/mingw32tdm --enable-cxx-
flags='-fno-function-sections -fno-data-sections' --with-pkgversion=tdm-1 --enable-sjlj-exceptions --with-bugurl=http://tdm-gcc.tdragon.net/bugs
Thread model: win32
gcc version 4.7.1 (tdm-1)

编辑


得到我的答案,正如cremno指出的,
%N
什么都不做,
%o
以八进制打印,因此在
%No
中,
N
被忽略,
%o
用于将传递的参数打印为八进制。剩下的问题是为什么不传递参数被视为
11
(十进制)。ASCII
11
中的FYI表示垂直选项卡。

您的printf格式字符串和参数不匹配;这会导致未定义的行为。任何事情都有可能发生。如果要打印文字
%%
,请在格式字符串中使用
%%

提供的答案是正确的,您的
printf
格式/参数不匹配,Windows/Linux句柄“未定义行为”非常不同。顺便说一句,这里有一个关于
%n
printf
格式说明符的作用以及它的有用性的链接:…@txtechhelp我的问题是,
%No
说明符在windows中代表什么?我已经纠正了不匹配的
printf
格式/参数。在这种情况下,
N
代表什么?我想这取决于链接的特定C库。据我所知,这对glibc来说并不重要,这可能就是为什么linux只是将其打印为字符串而不进行任何转换。
N
是MSVCRT中的长度修饰符。它代表
附近的
F
用于
far
。现在它们什么都不做,但在16位x86天内,它们就可以与
%s
%p
@Deduplicator:。@Nishant:您的术语是错误的
N
是长度修饰符(MS特定),而
o
是转换说明符(标准C)。而且,
%No
毫无意义。
#include <stdio.h>

int main(void) {
    // your code goes here
    printf(" %c %No %d",65,65,23);
    return 0;
}
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/program files (x86)/codeblocks/mingw/bin/../libexec/gcc/mingw32/4.7.1/lto-wrapper.exe
Target: mingw32
Configured with: ../../src/gcc-4.7.1/configure --build=mingw32 --enable-languages=c,c++,ada,fortran,objc,obj-c++ --enable-threads=win32 --enable-libgo
mp --enable-lto --enable-fully-dynamic-string --enable-libstdcxx-debug --enable-version-specific-runtime-libs --with-gnu-ld --disable-nls --disable-wi
n32-registry --disable-symvers --disable-build-poststage1-with-cxx --disable-werror --prefix=/mingw32tdm --with-local-prefix=/mingw32tdm --enable-cxx-
flags='-fno-function-sections -fno-data-sections' --with-pkgversion=tdm-1 --enable-sjlj-exceptions --with-bugurl=http://tdm-gcc.tdragon.net/bugs
Thread model: win32
gcc version 4.7.1 (tdm-1)