I have written a simple program to save details about a maximum of 20 people using structures.
But when i run it, gets gives me error.......
Here is the code...
// Hihi.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
#include<iostream>
#include<conio.h>
using namespace std;
struct address
{
char name[20];
int homeno;
char city[20];
char district[20];
char state[20];
long int pincode;
};
address addr[20];
int main()
{
cout<<"Enter the number of people"<<endl;
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"Enter the name"<<endl;
gets(addr[i].name);
cout<<"Enter the house number"<<endl;
cin>>addr[i].homeno;
cout<<"Enter the city"<<endl;
gets(addr[i].city);
cout<<"Enter the district"<<endl;
gets(addr[i].district);
cout<<"Enter the state"<<endl;
gets(addr[i].state);
cout<<"Enter the pincode"<<endl;
cin>>addr[i].pincode;
cout<<endl<<endl;
}
cout<<endl;
cout<<"Name\tHome No.\tCity\tDistrict\tState\tPincode"<<endl;
for(int i=0;i<n;i++)
{
cout<<addr[i].name<<"\t"<<addr[i].homeno<<"\t"<<addr[i].city<<"\t"<<addr[i].district<<"\t"<<addr[i].state<<"\t"<<addr[i].pincode<<endl;
}
getch();
return 0;
}
Now output:
Enter the number of people
1
Enter the name
Enter the house number
512
Enter the city
Enter the district
Blah Blah
Enter the state
Blah
Enter the pincode
69584
Name Home No. City District State Pincode
512 Blah Blah Blah 69584
See i didn't get the chance to type, the name & city, Even though all others are OK. What could be causing this.......