You want something like this (note-this does no error checking) -
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define NAMESIZE 50
struct list {
char name[NAMESIZE]; /* Holds the name of reference */
struct list *next_list; /* The next reference to name */
};
int fndnm(struct list *first_list, char *search)
{
struct list *look_list;
/* start with the first struct */
look_list = first_list;
while (1)
{
if (look_list == NULL)
return 0;
else if (strcmp(look_list->name,search)==0)
return 1;
else
look_list = look_list->next_list;
}
}
void DeleteList(struct list* head)
{
struct list* temp;
while(head!=NULL)
{
temp=head->next_list;
free(head);
head=temp;
}
}
int main()
{
int counter, yesno;
struct list *init_list,*walk_list;
char line[100];
/*create first list*/
init_list = malloc(sizeof(struct list));
walk_list = init_list;
for (counter = 0; counter < 5; ++counter)
{
struct list* temp;
printf("Enter a name: ");
fgets(line, sizeof(line), stdin);
line[strlen(line)-1] = '\0';
sprintf(walk_list->name, "%s", line);
/* allocate next list */
temp=malloc(sizeof(struct list));
temp->next_list=NULL;
walk_list->next_list=temp;
walk_list = temp;
}
printf("Now, enter a name to search: ");
fgets(line, sizeof(line), stdin);
line[strlen(line)-1] = '\0';
yesno = fndnm(init_list, line);
if (yesno)
printf("Found = TRUE");
else
printf("Found = FALSE");
/*clean up before exit*/
DeleteList(init_list);
return 0;
}