Today when compiling a C language program, for struct variables, report the error error:request for member ' xxx ' in something not a structure or union.
After debugging the discovery is. And so wrong.
If it is an address, just behind it with->, if it is not an address, it will be used behind it.
The code is abbreviated as follows:
#include <stdio.h>
#include <string.h>
typedef struct TEST_T
{
Char name[20];
int age;
}test_s;
void Test (test_s* mytest)
{
char* ptr = "Hello";
memcpy (Mytest->name, PTR, strlen (PTR)); MyTest is a struct pointer, so reference a variable using the struct pointer name, member variable name
Mytest->age = 20;
}
int main ()
{
test_s tt;
int ret = 0;
memset (TT, 0, sizeof (TT));
Test (&TT);
printf ("name:%s\n", tt.name); TT is a struct variable, so use "struct name. Member variable" to refer to a variable
printf ("age:%d\n", tt.age);
return ret;
}
C Language Error: Request for member ' xxx ' in something not a structure or union