gpt4 book ai didi

c - 访问 char*** 时出现问题

转载 作者:行者123 更新时间:2023-11-30 18:06:56 25 4
gpt4 key购买 nike

我试图访问 strcasestr 中的字符*,但似乎没有效果代码如下:

#define NUMOFADDTYPES 5

const char* milkAdditions[] = {"Cream", "Half-and-half", "Whole-Milk",
"Part-skim", "skim", "non-dairy", NULL};
const char* syrupAdditions[] = {"Vanilla", "Almond", "Raspberry", NULL};
const char* sweetenerAdditions[] = {"white-sugar", "sweetener",
"Raw-cane", "honey", NULL};
const char* spiceAdditions[] = {"Cinnamon", "cardamon", NULL};
const char* alcoholAdditions[] = {"Brandy", "Rum", "Whiskey",
"Aquavit", "Kahlua", NULL};

const char** additions[] = {milkAdditions, syrupAdditions,
sweetenerAdditions, spiceAdditions,
alcoholAdditions};



char *ptr;
int i, j;

printf("Dump of additions[j][i]\n");
for(j = 0; j < NUMOFADDTYPES; j++)
{
for(i = 0; (additions[j])[i] != NULL; i++)
{
printf("%d %d\t%s\n", j, i, additions[j][i]);
if((ptr = strcasestr((additions[j])[i], string)) != NULL)
{
ptr += strlen((additions[j])[i]);
getVolume(ptr);
}
}

输出是:

Dump of additions[j][i]
0 0 Cream
0 1 Half-and-half
0 2 Whole-Milk
0 3 Part-skim
0 4 skim
0 5 non-dairy
1 0 Vanilla
1 1 Almond
1 2 Raspberry
2 0 white-sugar
2 1 sweetener
2 2 Raw-cane
2 3 honey
3 0 Cinnamon
3 1 cardamon
4 0 Brandy
4 1 Rum
4 2 Whiskey
4 3 Aquavit
4 4 Kahlua

任何帮助将不胜感激

编辑:

抱歉没有添加

  char string[] = "AcceptAdditions: Cream;lots white-sugar;dash\r\n\r\n";
getAddition(string);

已解决

最佳答案

抱歉,我误读了手册页,并使用主字符串搜索子字符串

char *strcasestr(const char *haystack, const char *needle);

还是谢谢你的回答

关于c - 访问 char*** 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5232144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com