1. ## Need help

Hi all,
I have a hard time to figure out to code the program assignment below for my C course. I wish I could get a grade C for this class.

[CODE]
struct student
{
int ID;
char name[20];
int exam1;
int exam2;
int finalExam;
};
struct stuTable
{
int totalpoint;
int count;
struct student *stu;
} ;

int Search(struct stutable *T, int id, struct student **stud)
{
/*Purpose: locate and return a pointer to a student if the
student is found in the stuTable.
return 1 if student is found otherwise return 0 */

}
[\CODE]

What struct student **stud mean? and can anyone help to show me how to code for the Search() function.
C_dummy

2. Well, I am a little new at this but I had a similar question about this same context...so I'll give this a shot. I might do more harm than good but here goes....

The function definition:
int Search(struct stutable *T, int id, struct student **stud)

Assuming that the variables
stutable *A, *B; are declared.

when it's called, it's called like this.

So when you use the pointer in your function you use it like this:
(*stud)

or a practical example would be...
*stud = (*stud)->stu;
...to step through the list.

first make a copy of the head pointer so you can get back to the beginning of the list.

Then begin to search through each node of the list by stepping through the list in a while loop. You stop searching when you find the end of the list that you are searching through.

in the loop, test for the equality. if(id==(*stud)->stu.ID)
I think that's the correct useage of -> and . if your compiler complains, then I'm at least close.

hope this gives you enough information to ask more questions or to send me flaming mail.

3. I am quite clear about your explaining. Could anybody know how
to code the Search() function and explain clearly what
struct student **stud mean?

C-dummy

4. Originally posted by C-dummy
to code the Search() function and explain clearly what
struct student **stud mean?

C-dummy
stud is a pointer to a pointer to a struct of type student.

5. There's some good stuff on linked lists at
http://cslibrary.stanford.edu/105/

This was posted to one of my questions today.

6. I still struggling to code this Search() function. Any C expert out
there could help?
I think I will get a F on this program assignment for my C course.

Here is I am trying to code:

int Search(struct stuTable *T, int id, struct student **stud)
{
if (T->stu.ID == id)
{
*(stud->ID) = id;
return 1;
}
else
return 0;
}

I have tried my best, but I still vague understand about how
to deal with struct student **stu. I am doubt about my coding
for Search() function is correct, but that is just tryout.

C-dummy

7. c-dummy, it seems like you're just having a bit of trouble with your english, because everyone is saying the right stuff. what is your native language?

8. cdummy,

assuming that Key id is a character string and that Struct B is a struct that looks like this:

struct student{
char* name;
struct* student *NEXT;
};

..and your main() calls the routine like this.
Search(id, listexample); where 'id' is what you are looking for in the linked list and 'listexample' is the linked list
Here is an example of a this search routine involving pointers.
Code:
```int Search(Key id, Struct *B){
B=B->NEXT;  //move in from the (dummy) head node
while (B->next!=NULL){
if(strcmp(B->name, id)){
return 1;
}
else
{
B=B->NEXT;
}
}
return 0;
}```
now, in the case that function call is
Search (id, &listexample);
which is similar to your problem...

This means that you have to double dereference the pointer
in the function definition.
int Search(Key id, Struct **B){
*B=(*B)->NEXT; //move in from the (dummy) head node
while ((*B)->next!=NULL){
if(strcmp((*B)->name, id)){
return 1;
}
else
{
*B=(*B)->NEXT;
}
}
return 0;
}

essentially, I just wrote the essence of your search routine for you.

lastly, if you don't know why the first step I did in the example was to move in one link from the dummy node, then you still have alot to learn about simple lists.