请用c语言实现:一个单词表存放了五个表示颜色的英文单词,输入一个字母,在单词表中查找并输出所有以此字母开头的单词,若没有找到,输出Not Found。要求用指针数组和二级指针实现。
时间: 2024-05-05 08:15:46 浏览: 77
```c
#include <stdio.h>
#include <string.h>
#define MAX_LEN 20
#define COLOR_NUM 5
int main() {
char colors[COLOR_NUM][MAX_LEN] = {"red", "blue", "green", "yellow", "black"};
char letter;
char **p_colors[COLOR_NUM];
int i, j, count = 0;
printf("Please input a letter: ");
scanf("%c", &letter);
for (i = 0; i < COLOR_NUM; i++) {
p_colors[i] = &colors[i];
if (colors[i][0] == letter) {
count++;
}
}
if (count == 0) {
printf("Not Found\n");
} else {
printf("The colors starting with '%c' are:\n", letter);
for (i = 0; i < COLOR_NUM; i++) {
if ((*p_colors[i])[0] == letter) {
printf("%s\n", *p_colors[i]);
}
}
}
return 0;
}
```
阅读全文