关于无类型指针指向结构体变量的问题

时间:2008-05-09 19:06:56   来源:论坛整理  作者:  编辑:chinaitzhe
为了说明问题,我写了一小段测试代码
C/C code





Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/





#include <stdio.h>

#include <string.h>



typedef struct test 

{

    char a[10];

    char b[10];

}t;



void main()

{

    void *data;    //data指针必须声明为无类型

    t te;

    data=&te

    strcpy(te.a,"sdf");

    printf("%s\n",(*data).a);//我这写错了,我想知道如何用无类型指针获取结构体变量中的值?

}




网友回复:
C/C code





Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/





(*data).a

改成

((t *)data)->a

关键字:类型,指针,指向,结构,变量,

文章评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面