如何在c中打印符号的整数等价物



我正在尝试打印符号的整数等价物;:。和空白,但它不起作用

printf( "Following symbols ending with a whitespace: - = + /  ; : ? . [whitespace]n" );
printf( "%d, %d, %d, %d, %d, %d, %d, %d, %d, %dn", '-', '=', '+', '/', '', ';', ':', '?', '.', ' ' );

我已经成功打印出A-Z、A-Z、0-20和其他符号的整数等价物。然而,当我试图编译这一行时,从分号到右边的符号似乎出现了问题。我从VS 2019的命令提示符中收到以下错误。

IntegerValueOfChar.c(29): warning C4129: ' ': unrecognized character escape sequence
IntegerValueOfChar.c(31): error C2143: syntax error: missing ')' before 'constant'
IntegerValueOfChar.c(31): warning C4473: 'printf' : not enough arguments passed for format string
IntegerValueOfChar.c(31): note: placeholders and their parameters expect 10 variadic arguments, but 5 were provided
IntegerValueOfChar.c(31): note: the missing variadic argument 6 is required by format string '%d'
IntegerValueOfChar.c(31): error C2137: empty character constant
IntegerValueOfChar.c(31): error C2059: syntax error: ')'

如何解决此问题?我正在将notepad++与Visual Studio编译器一起使用。谢谢你帮助了一个失意的傻瓜

问题是反斜杠字符被用作字符常量和字符串文字中的转义前缀。要将实际的退格字符表示为字符常量或字符串文字中的字符,需要将其加倍:

printf( "Following symbols ending with a whitspace: - = + / \ ; : ? . [whispace]n" );
printf( "%d, %d, %d, %d, %d, %d, %d, %d, %d, %dn", '-', '=', '+', '/', '\', ';', ':', '?', '.', ' ' );

最新更新