鱼C论坛

 找回密码
 立即注册
查看: 1957|回复: 5

[已解决]C语言如何取指针数组中的某个元素的字符?

[复制链接]
发表于 2019-5-25 21:47:57 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 kingsxiu3 于 2019-5-25 21:57 编辑

        char *str[5]={

                "Austria",

                "United States",

                "United Kingdom",

                "Switzerland",

                "Canada"

        };

        char *(*ssha)[5]=&str;


我想用数组指针char *(*ssha)[5]=&str 取指针数组str的第1个元素即“United States”中的“S"这个字符并且把它打印出来该如何操作
最佳答案
2019-5-25 23:02:56
  1. #include <stdio.h>

  2. int main(void)
  3. {
  4.         const char *str[5] =
  5.         {
  6.                 "Austria",
  7.                 "United States",
  8.                 "United Kingdom",
  9.                 "Switzerland",
  10.                 "Canada"
  11.         };
  12.         const char *(*ssha)[5] = &str;

  13.         printf("%c\n", (*ssha)[1][7]);
  14.         return 0;
  15. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-5-25 22:17:29 | 显示全部楼层
*(*(str+1)+7)
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-5-25 22:18:11 | 显示全部楼层
  1. #include<stdio.h>

  2. int main()
  3. {
  4.   char *str[5]=
  5.   {
  6.     "Austria",

  7.     "United States",

  8.     "United Kingdom",

  9.     "Switzerland",

  10.     "Canada"

  11.   };
  12.   printf("%c\n",*(*(str+1)+7));
  13.   return 0;
  14. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-5-25 23:02:56 | 显示全部楼层    本楼为最佳答案   
  1. #include <stdio.h>

  2. int main(void)
  3. {
  4.         const char *str[5] =
  5.         {
  6.                 "Austria",
  7.                 "United States",
  8.                 "United Kingdom",
  9.                 "Switzerland",
  10.                 "Canada"
  11.         };
  12.         const char *(*ssha)[5] = &str;

  13.         printf("%c\n", (*ssha)[1][7]);
  14.         return 0;
  15. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-5-26 11:46:21 | 显示全部楼层
感谢你的回答 解开了困扰我的问题
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-5-26 11:47:00 | 显示全部楼层

感谢你的回答哦
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-5 09:30

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表