-->
Showing posts with label Program to understand concept of nested structure of struct.. Show all posts
Showing posts with label Program to understand concept of nested structure of struct.. Show all posts

Program to understand concept of nested structure of struct.

using codeblock
--------------------------------------------------------------------------------------
//understanding nested struct concept         //comment abt. program
#include <stdio.h>                            //header file to handle input and output
struct college                                //struct tag
{
    char name[50];                            //first member named name
    char address[50];                         //second member named address
};
struct student                               //second struct tag
{
char name[50];                              // member1
char stream[40];                            //member 2
struct college first;                       //acts as a member. It is a variable of first tag college
};
struct student info;
int main()
{
    printf("enter college name\n");
    gets(info.first.name);                 //accessing member of first tag for input
    printf("enter college address\n");
    gets(info.first.address);             //accessing member of first tag for input
    printf("enter student name\n");
    gets(info.name);                        //accessing member of second tag for input
    printf("enter student's stream\n");
    gets(info.stream);                      //accessing member of second tag for input
    printf("------------------------\n");
    printf(" college name is\n");
    puts(info.first.name);                   //display of data
    printf("college address is\n");
    puts(info.first.address);                 //display of data
    printf("student name is\n");
    puts(info.name);                           //display of data
    printf("student's stream is\n");
    puts(info.stream);                        //display of data
    return 0;
}
------------------------------------------------------------------------------------------------------------------

using turbo c++
---------------------------------------------------------------------------
//understanding nested struct concept         //comment abt. program
#include <stdio.h>                            //header file to handle input and output
#incluse<conio.h>
struct college                                //struct tag
{
    char name[50];                            //first member named name
    char address[50];                         //second member named address
};
struct student                               //second struct tag
{
char name[50];                              // member1
char stream[40];                            //member 2
struct college first;                       //acts as a member. It is a variable of first tag college
};
struct student info;
int main()
{
    printf("enter college name\n");
    gets(info.first.name);                 //accessing member of first tag for input
    printf("enter college address\n");
    gets(info.first.address);             //accessing member of first tag for input
    printf("enter student name\n");
    gets(info.name);                        //accessing member of second tag for input
    printf("enter student's stream\n");
    gets(info.stream);                      //accessing member of second tag for input
    printf("------------------------\n");
    printf(" college name is\n");
    puts(info.first.name);                   //display of data
    printf("college address is\n");
    puts(info.first.address);                 //display of data
    printf("student name is\n");
    puts(info.name);                           //display of data
    printf("student's stream is\n");
    puts(info.stream);                        //display of data
  getch();    
return 0;
}