I am just practicing my list writing skills. I wrote a few list funcs, such as addnew, lookup etc.
However, when it comes to implementing lookup in main funcs i am a bit cunfused as to what parameters i should use. here is my code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
typedef struct List { char *name; int value; struct List *next;} List;
List *newitem (char *name, int value)
{
List *newp;
newp = (List *)calloc(1,sizeof(List));
newp -> name = name;
newp -> value = value;
newp -> next = NULL;
return newp;
}
List *addfront (List *listp, List *newp)
{
newp -> next = listp;
return newp;
}
List *addtoend (List *listp, List *newp)
{
List *p;
if (listp == NULL)
return newp;
for (p = listp; p-> next != NULL; p = p -> next)
p -> next = newp;
return listp;
}
List *lookup (List *listp, char *name)
{
for ( ;listp != NULL; listp = listp -> next)
if (strcmp(name, listp -> name) == 0)
return listp;
return NULL;
}
int main (void)
{
char s;
char j[15];
List *K = NULL;
while (s != '.'){
s = getchar();
K = newitem (s,K);
}
printf("Type a name please:");
scanf("%s", j);
lookup(
}
what would i need to put into the lookup func after a name is read into the array?
thanks