Here is the code:
char *tempName;
cout<<"Enter the name you wish to compare: ";
cin>>tempName;
but I am getting some sort of memory error, how do you read directly into the character pointer???
Here is the code:
char *tempName;
cout<<"Enter the name you wish to compare: ";
cin>>tempName;
but I am getting some sort of memory error, how do you read directly into the character pointer???
Pointer variables hold addresses, they cant hold characters. You have to dereferecne the pointer. Your pointer is only a pointer to a chacter too...it needs to point to an array, and you need to allocate space either on the stack or heap for it...id show you but im sure somone else will and im too hung over...
-------------------
"Exception"
Code:#include <iostream.h> int main (void) { char TempChar[55]; char *pTempChar = &TempChar[0]; //Dereference cout<<"Enter the name you wish to compare: "; cin>>pTempChar; cout<<pTempChar<<'\n'; return 0; }
Last edited by Barjor; 04-25-2002 at 11:33 AM.
char * pTemp = new char[40];
cout << "enter name to be used in program";
cin >> pTemp;
If you use that solution you need to make sure you use delete when you are done with the char
or even better
Code:main() { char * pTemp = new char[40]; cout << "enter name to be used in program"; cin.getline(pTemp,40); cout<<pTemp; delete pTemp; system("pause"); return 0; }
Shouldnt that be delete[]?
I dunno since its a pointer....
yup, should be delete [] pTemp. If you use [] after new you use [] after delete.
yes i thought i had missed something huge in that code
***No meaning with subjetc****
just glad to see someone who voted for Nader!!!
Barjor!
who's nader?
@Barjor:
char *pTempChar = &TempChar[0]; //Dereference
TempChar is already a adress, so you only need:
char *pTempChar=TempChar;