- 论坛徽章:
- 0
|
看一下这段简单的代码:
1 #include<stdlib.h>;
2 typedef struct
3 { int *base;
4 int size;
5 }Test;
6 main()
7 { int i,*p;
8 Test *s;
9 s.base=(int *)malloc(8*sizeof(int));
10 s.size=8;
11 for(p=s.base,i=1;i<=8;i++,p++)
12 *p=i;
13 for(p=s.base,i=1;i<=8;i++,++p)
14 printf("%d\t",*p);
15 }
用gcc编译一下:
结果显示:
[wz@myhand tmp]$ gcc -o t4 t4.c
t4.c: In function `main':
t4.c:9: request for member `base' in something not a structure or union
t4.c:10: request for member `size' in something not a structure or union
t4.c:11: request for member `base' in something not a structure or union
t4.c:13: request for member `base' in something not a structure or union
为什么它会说s.base和s.size有问题呢?
若要实现上面的目的,该用什么样的方法解决呢? |
|