免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1096 | 回复: 0
打印 上一主题 下一主题

[C] 数组指针 学习 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-06-19 16:24 |只看该作者 |倒序浏览
本帖最后由 horse285 于 2014-06-19 16:50 编辑
  1. #include <stdio.h>
  2. #include <stdlib.h>[p=30, 2, left][/p]
  3. #include <string.h>
  4. #include <unistd.h>
  5. typedef struct
  6. {
  7. int i;
  8. char(*p)[1024];
  9. }_st_sz;

  10. int test(_st_sz **pst)
  11. {
  12.     char (*p)[1024] = NULL;
  13.     char (*p1)[1024] = NULL;

  14.     printf("sizeof(p)=%ld,sizeof(*P)= %ld\n",sizeof(p), sizeof(*p));

  15.     p = malloc(2*sizeof(*p));
  16.     p1=p;
  17.     (*pst)->p=p;

  18.     strcpy(p[0],"abc");
  19.     strcpy(p[1],"efg");
  20.     strcpy(p[2],"hij");

  21.     //printf("p =%p,p =%s\n",p,p);
  22.     printf("*p=%p,*p=%s\n",*p,*p);
  23.     printf("p[0]=%s,(*p)[0]=%c,(*p)[1]=%c\n",p[0],(*p)[0],(*p)[1]);
  24.     printf("p[0]=%s,*p[0]  =%c,*p[1]=  %c, *p[2]=%c\n",p[0],*p[0],*p[1],*p[2]);
  25.     printf("p[1]%s, *p[1]=%c\n\n",p[1],*p[1]);

  26.     printf("*p++=%s\n",*p++);

  27.     while (p1!=NULL&&strcmp(*p1,"")!=0)
  28. {
  29.         char *p2=NULL;
  30.         p2=*p1;
  31.         while((*p2) != NULL)
  32.         {
  33.             printf("%c.",*(p2++));
  34.         }
  35.         printf("\n");

  36.         printf("%s\n",*(p1++));
  37.     }

  38.     return 0;
  39. }


  40. int main()
  41. {

  42.     _st_sz *pstSz = malloc(sizeof(_st_sz ));
  43.     char (*p1)[1024] =NULL;

  44.     test(&pstSz);
  45.     p1=pstSz->p;
  46. printf("\n\n");

  47.     while (p1!=NULL&&strcmp(*p1,"")!=0)
  48.     {
  49.         char *p2=NULL;
  50.         p2=*p1;
  51.         while((*p2) != NULL)
  52.         {
  53.             printf("%c.",*(p2++));
  54.         }
  55.         printf("\n");
  56. printf("%s\n",*(p1++));
  57.     }

  58.     free(pstSz->p);
  59.     free(pstSz);
  60.     return 0;
  61. }

复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP