can someone tell me whats wrong with this codes, because there's some error in printing..

#include<stdio.h>
#include<iostream.h>

struct bday{
	char month[2];
	char date[2];
	char year[4];
};

struct contacts{
	char surname[10];
	char phoneno[12];
};

void main(void)
{
	struct contacts con[2];
	struct bday bd[2];
	int i;

	for(i=0;i<=2;i++)
	{
		cout<<"\nSurname       : ";
		cin>>con[i].surname;
		cout<<"Phone number  : ";
		cin>>con[i].phoneno;
		cout<<"Birthday month: ";
		cin>>bd[i].month;
		cout<<"Birthday date : ";
		cin>>bd[i].date;
		cout<<"Birthday year : ";
		cin>>bd[i].year;
	}

	for(i=0;i<=2;i++)
	{
		cout<<"\nContact #"<<i<<"surname     :"<<con[i].surname;
		cout<<"\nContact #"<<i<<"phone number: "<<con[i].phoneno;
		cout<<"\nContact #"<<i<<"Birthday    : "<<bd[i].month<<"/"<<bd[i].date<<"/"<<bd[i].year;
		cout<<"\n\n";   
	}
}

>>for(i=0;i<=2;i++)
That will print 3 structures, not 2. what you want to do is use the < operator, not the <= operator.

My assumption (since I've been up all night that's all I'm going to do now) is that it's in print, it's in saving.

Your initializations of con and bd should simply be contacts con[2]; and bday bd[2]; . Also, you are trying to save 3 contacts yet you only initialize your arrays for 2. Either change your arrays to 3 or set your for so they run till i < 2.

No void main. Main should be int and returns 0 if it works. You can cause some big issues with void I've heard. More on it here:
http://www.daniweb.com/forums/thread78955.html

thanks..it is slightly working now..
the struct bday has an error in printing..it should print like this 02/05/2009 but it prints like this 02052009/0205/2009..
can you tell me the problems

The structure is wrong -- need to add another character to each element for the null-terminator

struct bday{
	char month[3];
	char date[3];
	char year[5];
};

or just make them ints

struct bday{
	int month;
	int date;
	int year;
};
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.