0

Hi guys!

I want the user to enter the day, month and year in a dd/mm/yyyy format.
But what i've written doesn't seem to work.

Code:

char d[2];
char m[2];
char y[4];

cout << "Day:";
gets(d);
cout << "Month:";
gets(m);
cout << "Year:";
gets(y);

In the output, it doesn't stop for Day, Goes for month.. and suddenly program crashes at Year. Any Help?

2
Contributors
2
Replies
8
Views
7 Years
Discussion Span
Last Post by anuragcoder
0

why are you using character arrays instead of integers?

why are you using C's gets() function instead of c++ cin?

If you really really want to use character arrays then you need to make them larger -- you have to account for the string's NULL terminating character. With integers you don't have to worry about that.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.