我试图在字符串中使用下划线,但它似乎使编译器将更少的字节分配给char数组并在关闭的char('\ 0')上运行。在字符串中使用下划线
这是什么原因造成的? 有没有办法转义下划线字符?
谢谢。
更多信息,请参见下面的代码:
code:
#include<stdio.h>
#define ARRSIZE 6
char str_ex[][ARRSIZE] = {"aaaa", "bbbb_bbbb", "cccc", "dddd", "ffff_ffff", "eeee"};
int main(void)
{
int i;
for(i=0; i<ARRSIZE; i++)
printf("%s\n", str_ex[i]);
return 0;
}
compile:
[email protected]:~/test$ gcc -g test.c -o test -Wall -ansi
test.c:4:1: warning: initializer-string for array of chars is too long [enabled by default]
test.c:4:1: warning: (near initialization for ‘str_ex[1]’) [enabled by default]
test.c:4:1: warning: initializer-string for array of chars is too long [enabled by default]
test.c:4:1: warning: (near initialization for ‘str_ex[4]’) [enabled by default]
output:
[email protected]:~/test$ ./test
aaaa
bbbb_bcccc
cccc
dddd
ffff_feeee
eeee
Welp。这不符合你的想法。而且,下划线几乎是错误的。 “这是一个编译器错误” - 事实并非如此。 – 2012-12-08 13:25:59
(地球上如何获得2 upvotes?) – 2012-12-08 13:30:32