【发布时间】:2013-07-06 04:32:50
【问题描述】:
我必须编写一个接收 2 个双指针(均为 char 类型)的函数。第一个双指针有一个查询值字符串,第二个有停用词。这个想法是从查询字符串中消除停用词并返回所有没有这些停用词的单词。
例如
输入 - 查询:“the”、“new”、“store”、“in”、“SF”
stopwords: “the”, “in”
输出 新的 店铺 顺丰
我在尝试使用 strtok 时编写了以下代码,它只接受指向 char 类型的单个指针。如何访问双指针的内容?
谢谢
#include <stdio.h>
void remove_stopwords(char **query, int query_length, char **stopwords, int stopwords_length) {
char *final_str;
final_str = strtok(query[0], stopwords[0]);
while(final_str != NULL)
{
printf("%s\n", final_str);
final_str = strtok(NULL, stopwords);
}
}
【问题讨论】:
-
您也可以这样做:
final_str=strtok(*query,*stopwords);和final_str=strtok(NULL,*stopwords);在 strtok 的情况下已在答案中描述了休息 -
@PHIfounder:您建议的 strtok 调用将使用
stopwords数组的第一个字符串中的字母作为分隔符拆分query数组中的第一个字符串,我认为这不是 OP 的意图。 -
@Simon 这就是我把它写成评论的原因。
-
指向指针的指针不是“双指针”......这是不正确且令人困惑的术语。
-
@JimBalter 是的,起初我以为它是指向
double的指针。
标签: c string double-pointer