empcode is declared as 5 characters. Since these are C strings, each C string must be terminated by a null character. You inputted 5 characters. Consequently, there was no place to store the null character. When you went to print empcode, it printed until it found a null character (which was at the end of POOJA).
Solution: Use C++ std::string instead of C strings.
BTW, main() must be type int.
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <string>
#include <iostream>
usingnamespace std;
int main()
{
struct person
{ string empcode;
string name;
int age;
float sal;
};
...
"Since these are C strings, each C string must be terminated by a null character. You inputted 5 characters. Consequently, there was no place to store the null character."
Thanks a ton! This was the mistake I made....I changed the declaration to :
char empcode[6];
and it worked!
However, I also tried declaring empcode as a string...but it showed error while compiling.