大河之jian 发表于 2020-3-1 11:52:30

通过指针输出结构体变量的内容

#include<stdio.h>
#include<stdlib.h>
struct student
{
        int ID;
        char name;
};
int main()
{
        struct stdent *p;
        struct student first
                ={2016080227,"Tom"};
        p=&first;
        printf("%\n ID is %d",(*p).ID);
        printf("\n name is %s",(*p).name);
        return 0;
}


编译
c(13) : warning C4133: '=' : incompatible types - from 'struct student *' to 'struct stdent *‘
c(14) : error C2037: left of 'ID' specifies undefined struct/union 'stdent'
c(15) : error C2037: left of 'name' specifies undefined struct/union 'stdent'

最后的魁拔 发表于 2020-3-1 11:57:58

第一:struct stdent *p;是student
第二:printf("%\n ID is %d",(*p).ID);把前面的%号去掉

大河之jian 发表于 2020-3-1 12:20:09

最后的魁拔 发表于 2020-3-1 11:57
第一:struct stdent *p;是student
第二:printf("%\n ID is %d",(*p).ID);把前面的%号去掉

谢谢
页: [1]
查看完整版本: 通过指针输出结构体变量的内容