Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

C Programming: Elementary Doubt in structure

Status
Not open for further replies.

Plzhelp

Junior Member level 3
Joined
Feb 18, 2012
Messages
31
Helped
7
Reputation
14
Reaction score
6
Trophy points
1,288
Location
India
Activity points
1,535
Hi All,

Just started doing C programming recently. I will be glad if anyone can help me out with my problem.

I have structure named PERSON. Inside this I have Name and Age.
I have another Structure called SCHOOL which has Location and Year.

Now I want to point to this struct called SCHOOL from inside of the struct PERSON and use its members. How do I do it??

Please give me some hint on this ASAP.

Thank You.
 

#include "stdafx.h"
#include "string.h"

struct school
{
char location[10];
int year;
};

struct person
{
char name[10]; // Member1
int age; // member2
struct school s1; // member 3 which is a struct(school) declared inside
};

int _tmain(int argc, _TCHAR* argv[])
{
struct person p; // Struct person variable declared here
p.s1.year=1998; // Member initialised here
strcpy(p.s1.location, "INDIA"); // Member initialised here
printf("\n %s %d", p.s1.location, p.s1.year);
return 0;
}
 

for that you have to declare a variable of structure school into person by that you can use its member
such as
struct school
{
// code
}

struct person
{
//some code
struct school s;
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top