警告:多字符字符常量 |

/* Beginning 2.0 */ #include main() { printf(" %d signifies the %c of %f",9,'rise',17.0); return 0; } 

大家好

当我编译它时,编译器发出以下警告:

 warning: multi-character character constant [-Wmultichar]| 

输出只打印e而不是rise

C中不允许多个字符?

如何打印整个单词( rise )?

请帮帮我。

尝试: printf(" %d signifies the %s of %f",9,"rise",17.0);

C区分字符( 一个字符)和字符串 (可包含任意数量的字符)。 您使用单引号( '' )表示字符文字,但使用双引号表示字符串文字。

同样,您指定%c来转换单个字符,但指定%s来转换字符串。

使用%s""作为字符串:

 printf(" %d signifies the %s of %f",9,"rise",17.0); ^^ ^ ^ 

对于'rise' ,这是有效的ISO 9899:1999 C. 它使用-Wall在gcc下编译时没有警告,并且在-pedantic使用“multi-character character constant”警告进行-pedantic

根据标准( §6.4.4.4.10 ),

  • The value of an integer character constant containing more than one character (eg, 'ab'), [...] is implementation-defined.