Can't fill char [80] using strings less than 80

HI Everyone .
I have a class :
1
2
3
4
5
6
7
class person 
{
private :
char Name [80] ;
public :
void set_firstname (char input [80]) {*Name = *input;}
}


and there is a function in another file which reads a single line from a file (which is the name of a person) and sets it to "person"'s Name:
1
2
3
4
5
6
7
8
9
string temp ;
char tempc [80];
person tmep1 ;
fstream ticketfile;
ticketfile.open("ticket.txt", ios::in);
getline(ticketfile, temp);
strcpy_s(tempc, temp.c_str());
temp1.set_firstname(tempc);


but this doesn't work.
when I do cout << temp1.get_firstname() I don't get the name I want .
Instead the first character is copied correctly , but the other 79 characters are a strange character ;
what is the problem ?
The names are not 80 character , they are usually 5 or 6 .

I can't use strings , because they have problems with binary files . thanks !
 
*Name = *input;

This will only copy the first character in the array. Use std::strcpy or similar functions to copy the strings.
Thank you my friends :)
Topic archived. No new replies allowed.