-
pointer
hi
My question is: I have a struct which is called Pet. data members name,type,age and a pointer variable nextPet.
I must write a function that dynamically creats a new node for a Pet object. The function should ask to user to enter in the information for all data members of the node, and assign NULL to the nextPet data member. I wrote but it gives a error.
here is the program...
#include <iostream>
struct Pet
{
char name;
char type;
int age;
node *nextPet;
};
int main( )
{
Pet *nextPet;
nextPet=new Pet;
cout<<"please write name"<<endl
cin>>nextPet->name;
cout<<"please write animal type"<<endl;
cin>>nextPet->type;
cout<<"please write age<<endl;
cin>>nextPet->age;
root->next=NULL;
RETURN 0;
}
pls help...thnks
-
hi again..
I made some changes in my program..but still it is not run correctly...
#include <iostream>
struct Pet
{
char name;
char type;
int age;
Pet *nextPet;
};
int main( )
{
Pet *nextPet;
nextPet=new Pet;
cout<<"please write name"<<endl;
cin>>nextPet->name;
cout<<"please write animal type"<<endl;
cin>>nextPet->type;
cout<<"please write age"<<endl;
cin>>nextPet->age;
nextPet=NULL;
return 0;
}
please help me. thanks
-
What kind of error are you getting???
You might need to declare your char name and char type as char name[20] and char type[10] or you could use a string class like
#include <string.h>
String name;
String type;
or if you have it (which is definately better)
#include <apstring.h>
apstring name;
apstring type;