我尝试在字符串中使用下划线,但它似乎使编译器为 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:
user@ubuntu:~/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:
user@ubuntu:~/test$ ./test
aaaa
bbbb_bcccc
cccc
dddd
ffff_feeee
eeee