//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();
}
#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