【发布时间】:2017-09-11 07:59:21
【问题描述】:
我昨晚凌晨 3 点起床编码,今天醒来,在源文件中找到了这个:(诅咒词已编辑)
void append_this_stuff(char *stuff_to_append_to[], char **stuff_to_append, int position) {
char the_actual_stuff[] = *(stuff_to_append_to);
char *screw_me = *(stuff_to_append);
int someNumber = strlen(screw_me);
int j = 0;
for (int i = position; i < (someNumber + position - 1); i++) {
the_actual_stuff[i] = (screw_me + j);
j++;
}
stuff_to_append_to = &the_actual_stuff;
}
当我尝试编译它时,我得到了这个错误:
<project root>/src/brstring.c: In function ‘append_this_stuff’:
<project root>/src/brstring.c:38:28: error: invalid initializer
char the_actual_stuff[] = *(stuff_to_append_to);
^
<project root>/src/brstring.c:46:24: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
the_actual_stuff[i] = (screw_me + j);
^
<project root>/src/brstring.c:50:21: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
stuff_to_append_to = &the_actual_stuff;
有人知道我这样做是否正确吗?我正在通过 C99 标准和 cmake 进行编译,并且我在 Fedora Linux 上使用 GCC,如果这会影响任何事情的话。
【问题讨论】:
-
你为什么用c99? C11 出来很久了,得到了广泛的支持。
标签: c string char concatenation c99