C Language Error: Request for member ' xxx ' in something not a structure or union

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.