- 论坛徽章:
- 0
|
本帖最后由 horse285 于 2014-06-19 16:50 编辑
- #include <stdio.h>
- #include <stdlib.h>[p=30, 2, left][/p]
- #include <string.h>
- #include <unistd.h>
- typedef struct
- {
- int i;
- char(*p)[1024];
- }_st_sz;
- int test(_st_sz **pst)
- {
- char (*p)[1024] = NULL;
- char (*p1)[1024] = NULL;
- printf("sizeof(p)=%ld,sizeof(*P)= %ld\n",sizeof(p), sizeof(*p));
- p = malloc(2*sizeof(*p));
- p1=p;
- (*pst)->p=p;
- strcpy(p[0],"abc");
- strcpy(p[1],"efg");
- strcpy(p[2],"hij");
- //printf("p =%p,p =%s\n",p,p);
- printf("*p=%p,*p=%s\n",*p,*p);
- printf("p[0]=%s,(*p)[0]=%c,(*p)[1]=%c\n",p[0],(*p)[0],(*p)[1]);
- printf("p[0]=%s,*p[0] =%c,*p[1]= %c, *p[2]=%c\n",p[0],*p[0],*p[1],*p[2]);
- printf("p[1]%s, *p[1]=%c\n\n",p[1],*p[1]);
- printf("*p++=%s\n",*p++);
- while (p1!=NULL&&strcmp(*p1,"")!=0)
- {
- char *p2=NULL;
- p2=*p1;
- while((*p2) != NULL)
- {
- printf("%c.",*(p2++));
- }
- printf("\n");
- printf("%s\n",*(p1++));
- }
- return 0;
- }
- int main()
- {
- _st_sz *pstSz = malloc(sizeof(_st_sz ));
- char (*p1)[1024] =NULL;
- test(&pstSz);
- p1=pstSz->p;
- printf("\n\n");
- while (p1!=NULL&&strcmp(*p1,"")!=0)
- {
- char *p2=NULL;
- p2=*p1;
- while((*p2) != NULL)
- {
- printf("%c.",*(p2++));
- }
- printf("\n");
- printf("%s\n",*(p1++));
- }
- free(pstSz->p);
- free(pstSz);
- return 0;
- }
复制代码 |
|