T
Tommy Lang
Hi!
I am trying to write a function that goes through an array of
objects(class Student) and checks if
object name(student name)matches search string(char *). I want the
function to return a pointer to the object, if a match is found.
This is my code so far...(am I even close? )
//I want to return a ponter of type student
Student *List::find(char *chName) //chName is the name i want to look
for
{
//Check whole array
for(int i=0;i<100;i++)
{
Student *temp;//Create a temp pointer
temp = MyArray; //Add current array value(object) to temp
char *name;//Create a char pointer
name = temp->get_name();//Get object name (public method of
Student)
if(name == chName)//Compare names
{
return temp; //return pointer to object if found
}
}
return NULL; //return NULL if it was not found
}
A correct call would be ...???
Student *s = find(NameToFind);
if(s!=NULL)
//do something....
Thx,
Tommy
I am trying to write a function that goes through an array of
objects(class Student) and checks if
object name(student name)matches search string(char *). I want the
function to return a pointer to the object, if a match is found.
This is my code so far...(am I even close? )
//I want to return a ponter of type student
Student *List::find(char *chName) //chName is the name i want to look
for
{
//Check whole array
for(int i=0;i<100;i++)
{
Student *temp;//Create a temp pointer
temp = MyArray; //Add current array value(object) to temp
char *name;//Create a char pointer
name = temp->get_name();//Get object name (public method of
Student)
if(name == chName)//Compare names
{
return temp; //return pointer to object if found
}
}
return NULL; //return NULL if it was not found
}
A correct call would be ...???
Student *s = find(NameToFind);
if(s!=NULL)
//do something....
Thx,
Tommy