如何在c中打印符号的整数等价物?
How to print the integer equivalent of symbols in c?
我正在尝试打印符号的整数等价物; :? .和空格,但它不起作用。
printf( "Following symbols ending with a whitespace: - = + / \ ; : ? . [whitespace]\n" );
printf( "%d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n", '-', '=', '+', '/', '\', ';', ':', '?', '.', ' ' );
我已经成功打印出 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, %d\n", '-', '=', '+', '/', '\', ';', ':', '?', '.', ' ' );
我正在尝试打印符号的整数等价物; :? .和空格,但它不起作用。
printf( "Following symbols ending with a whitespace: - = + / \ ; : ? . [whitespace]\n" );
printf( "%d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n", '-', '=', '+', '/', '\', ';', ':', '?', '.', ' ' );
我已经成功打印出 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, %d\n", '-', '=', '+', '/', '\', ';', ':', '?', '.', ' ' );