#include<stdio.h>
//This program is about structure and there pointer
//
typedef struct{
int i;
char c;
}str1,*strptr;
str1 str[5];
strptr *ptr;
int main(){
ptr = &str;// This is shown as incompatible type assignment **warning**
ptr->i=35; // **error**: request for member 'i' in something
//not a structure or union
ptr->c='d';//**error**: request for member 'c' in
// something not a structure or union
printf("My structure values are %d %c\n",str[0].i,str[0].c);
return 0;
}
当我运行这个程序时,出现了一个警告和两个错误。请阅读警告和错误的注释行。
我错过了什么?
最佳答案
在您的代码中,strptr
已经是一个指针类型。你需要改变
strptr *ptr;
到
strptr ptr;
关于c - 如何使用结构指针变量的typedef指向同一个结构变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31692897/