您的位置:首页 > 大数据 > 人工智能

指针数组--main参数

2016-06-24 10:35 351 查看
#include <stdio.h>
#include <string.h>

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

int lookupKeyword(const char* key,const char* table[],const int size)
{
int ret = -1;
int i = 0;
for(i=0;i<size;i++)
{
if(strcmp(key,table[i])==0)
{
ret = i;
break;
}
}

return ret;
}

int main(void)
{

const char* keyword[] ={
"do",
"for",
"if",
"while"
};

printf("index = %d\n",lookupKeyword("for",keyword,DIM(keyword)));
printf("index = %d\n",lookupKeyword("main",keyword,DIM(keyword)));

printf("----end----\n");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: