#include<iostream>
#include<cstring>
usingnamespace std;
class player
{
private:
char firstname[20];
public:
void setfname (char name[])
{
strcpy (firstname, name);
}
char getFname (void) {return firstname[20];}
};
int main(void)
{
player keith;
char fname[19];
cout<<"what is ur first name";
cin>>fname;
keith.setfname(fname);
cout<<keith.getFname();
}
as you can guess i am trying to code a simple input ur first name and display ur first name program here. However, it display nothing no matter what i enter can anyone please point out my problem?
getFname is returning a single character, not the entire string. And the character it is returning is the 21st character in the array, which contains only 20 characters.