请用C语言写下列代码:使用指针数组创建一个含有月份英文名的字符串数组,并使用指向指针的指针指向这个字符串数组,实现输出数组中的指定字符串。 char *Month[]={ /*定义字符串数组*/ "January", "February", "March", "April", "May", "June", "Junly", "August", "September", "October", "November", "December" }; 程序运行结果示例: 输入:Input a number for month 7 输出:The month is:Junly 输入提示:"Input a number for month\n" 输入格式:"%d" 输出提示:"The month is:" 输出格式:"%s\n"
时间: 2023-07-05 07:32:10 浏览: 212
C语言指针的左右法制
下面是使用指针数组创建字符串数组,并使用指向指针的指针输出指定字符串的C语言代码:
```c
#include <stdio.h>
int main()
{
char *Month[] = {
"January",
"February",
"March",
"April",
"May",
"June",
"Jul",
"August",
"September",
"October",
"November",
"December"
};
char **p = Month; // 指向指针的指针指向字符串数组
int n;
printf("Input a number for month\n");
scanf("%d", &n);
if (n >= 1 && n <= 12) {
printf("The month is:%s\n", *(p + n - 1)); // 输出指定字符串
} else {
printf("Invalid input\n");
}
return 0;
}
```
程序运行结果示例:
```
Input a number for month
7
The month is:Jul
```
阅读全文