Aks*_*til 0 c struct pointers typedef
#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;
}
Run Code Online (Sandbox Code Playgroud)
当我运行这个程序时,会出现一个警告和两个错误.请阅读注释行以获取警告和错误.
我错过了什么?
在您的代码中,strptr已经是指针类型.你需要改变
strptr *ptr;
Run Code Online (Sandbox Code Playgroud)
至
strptr ptr;
Run Code Online (Sandbox Code Playgroud)