Saturday, 21 January 2017

Tutorial Showing Nested Of Structure -Example Of Nested Of Structure In C++

//tested on Dev C++
#include<iostream>
#include<conio.h>
#include<stdio.h>
using namespace std;
void get();
void disp();
FILE *f;

struct address
{
       char add[50];
       };
struct details
{
       int salary;
       char name[20];
       address a;
       }d;
       void get()
       {
            f=fopen("C://student.txt","w");
            cout<<"Enter Name:";
            gets(d.name);
            cout<<"Enter Salary:";
            cin>>d.salary;
            fflush(stdin);
            cout<<"Enter Address:";
            gets(d.a.add);
            fwrite(&d,sizeof(d),1,f);
            
            }
            void disp()
            {
                 cout<<"Name: "<<d.name;
                 cout<<"\nSalary: "<<d.salary;
                 cout<<"\nAddress: "<<d.a.add;
                 }
       main()
       {
          get();
          disp();
          getch();
          }   

No comments:

Post a Comment

Amazon1Ads