Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Arrays to a constructor

Status
Not open for further replies.

WarrenB

Programmer
Feb 7, 2001
38
GB
I've got this piece of code and it doesn't appear to be passing properly

heres the constructor:

password::password (char input[14])
{
pass[14] = input[14];
}

and the line calling it + input:

cin.getline(x,15);
password check(x);

when the contents of pass are viewed all that appears is garble. There is no comppile error or warnings. Any ideas? thanks in advance. Warren Brown
wazzer@btinternet.com
 
It must be like this:

...
password::password (char input[]) // that is the way for this signature
{
pass[14] = input[14];
}

and the line calling it + input:

char x[15];
cin.getline(x,15);
password check(x);
Best Regards,

aphrodita@mail.krovatka.ru {uiuc rules}
 
thanks, i'll give it a try :) Warren Brown
wazzer@btinternet.com
 
Wait a minute, have you overloaded the assignment operator or something? if you are going to copy the input string you'd better use strcpy(char*,char*);
Is this what you are trying to do?

char *x=new char[15];
cin.getline(x,15);
password check(x);

password::password(char* input){

strcpy(pass,input); //copy string input to string pass
}
 
In above case, what psnead has done is right, and i'ld rec to follow the same. And I also guess that pass is/should be array i.e. char pass[14], and not char* pass. Or it gives a null pointer assignment, at times.
Hemant.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top