define _CRT_SECURE_NO_WARNINGS

include

include

include

/ const char table[] 指针数组 / int searchKeyTable(const char table[], const int size, const char key, int pos) { int rv = 0; int i = 0; int inum = 0; if (table == NULL || key == NULL || pos == NULL) { rv = -1; printf(“func searchKeyTable:%d”, rv); return rv; }

  1. inum = (sizeof(table) / sizeof(*table));
  2. for (i = 0; i < size; i++) {
  3. if (strcmp(key, table[i]) == 0) {
  4. *pos = i;
  5. return rv;
  6. }
  7. }
  8. // 没有找到返回-1
  9. if (i == size) {
  10. *pos = -1;
  11. }
  12. return rv;

}

define DIM(a) (sizeof(a)/sizeof(*a))

void main() { int inum = 0; int pos = 0; int a[10]; int i = 0;

  1. // 自我约束能力 '\0' NULL 0
  2. char* c_keyword[] = {
  3. "while",
  4. "case",
  5. "static",
  6. "do",
  7. '\0'
  8. };
  9. //带参数的宏
  10. searchKeyTable(c_keyword, DIM(c_keyword), "do", &pos);
  11. printf("pos:%d\n", pos);
  12. for (i = 0; c_keyword[i] != NULL; i++) {
  13. printf("%s\n", c_keyword[i]);
  14. i++;
  15. }
  16. system("pause");
  17. return;

}