【发布时间】:2015-04-08 15:24:40
【问题描述】:
所以我一直无法理解 C 中的指针。我的问题是如何让 char * find_ch_ptr 返回一个 char*。我也一直在到处遇到演员问题。如果这里有什么问题,请您详细解释一下吗?
/*
* Return a pointer to the first occurrence of <ch> in <string>,
* or NULL if the <ch> is not in <string>.
*****
* YOU MAY *NOT* USE INTEGERS OR ARRAY INDEXING.
*****
*/
char *find_ch_ptr(char *string, char ch) {
char * point = (char*)(string + 0);
char * c = &ch;
while(point != '\0') {
if(point == c) return (char*)point;
else *point++;
}
return (char*)point; // placeholder
}
【问题讨论】:
-
您不需要将
char*转换为char*。 -
你不需要任何演员表,
else *point++也可以,就像else point++;一样 -
你不是说*point++ 你是说point++
-
@pm100;效果是一样的。
-
感谢大家的帮助!