【发布时间】:2013-11-24 17:09:52
【问题描述】:
所以如果我在 C 中有以下 char 数组:
"a b c" // where "a", "b", and "c" can be char arrays of any length and the
// space between them can be of any length
如何删除“a”标记,但将其余的“b c”存储在 char 指针中?
到目前为止,我已经实现了以下不起作用的方法:
char* removeAFromABC(char* a, char* abc) {
char* abcWithoutA[MAXIMUM_LINE_LENGTH + 1];
int numberOfCharsInA = strlen(a);
strcpy(abcWithoutA, (abc + numberOfCharsInA));
return abcWithoutA;
}
【问题讨论】:
-
怎么样:
char *str_minus_sw = &(your_array+2);? -
但问题是“sw”并不总是第一个字符
-
你能简单地将指针前进到数组中的下一个字符吗?
-
char* abcWithoutA[MAXIMUM_LINE_LENGTH + 1];声明了一个MAXIMUM_LINE_LENGTH + 1字符指针数组,而不是常规字符数组。删除字符后的*...
标签: c string tokenize strtok arrays