2条回答 默认 最新
- 小P聊技术 2021-06-01 17:02关注
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <string.h> #define NUM(a) (sizeof(a)/sizeof(*a)) int searchKeyTable(const char* table[], const int size, const char* key, int* pos) { if (table == NULL || key == NULL || pos == NULL) { return -1; } int n = -1; for (int i = 0; i < size; i++) { if (strcmp(table[i], key) == 0) { n = i; break; } } if (n == -1) { printf("无此字符串\n"); return -2; } *pos = n + 1; return 0; } int main() { char* keywords[] = { "while", "case", "static", "do" }; int ret = 0; int size = NUM(keywords); int pos = 0; char* key = "do"; ret = searchKeyTable(keywords, size, key, &pos); if (ret != 0) { printf("searchKeyTable error:%d\n", ret); return ret; } printf("'%s'的位置是:%d\n", key, pos); printf("\n"); system("pause"); return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 2024-五一综合模拟赛
- ¥15 下图接收小电路,谁知道原理
- ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
- ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
- ¥15 手机接入宽带网线,如何释放宽带全部速度
- ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
- ¥15 ETLCloud 处理json多层级问题
- ¥15 matlab中使用gurobi时报错
- ¥15 这个主板怎么能扩出一两个sata口
- ¥15 不是,这到底错哪儿了😭