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

标签 c

我试图访问 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/

相关文章:

c++ - 无法通过 C 中的 UDP 套接字接收完整整数数组

c - 使用网络内核扩展监控网络数据包

c++ - 可执行文件和共享库可以包含同名函数吗?

Code::Blocks 不解析 header #define

c - 什么时候将局部静态变量存储在内存中?

c - 为什么我的宏不能编译?

c - 插入 AVL 树 : segmentation fault error

c++ - 如何从 COFF 目标文件中读取函数代码?

c - 套接字 send() 可重复

本地系统管理员下的 CreateProcessAsUser 返回 "5: acces denied"