Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*-----------------------------
- Program 9 by Rebecca VanderClute
- -----------------------------*/
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- #include "leak.h"
- struct node
- {
- int data;
- struct node *next;
- };
- struct node *searchList(int value, node *head);
- int main()
- {
- struct node *first, *current, *temp;
- first = calloc(1, sizeof(struct node));
- current = first;
- int i = 0;
- for (i = 0; i < 9; i++)
- {
- temp = calloc(1, sizeof(struct node));
- temp->data = i;
- current->next = temp;
- current = current->next;
- }
- current = first->next;
- printf("Printing node values...\n");
- while (current)
- {
- printf("%d\n", current->data);
- current = current->next;
- }
- int search = 0;
- printf("-----------------\n");
- printf("Please enter a value to search for: ");
- scanf("%d", &search);
- current = first->next;
- printf("[%d %d]\n", search, searchList(search, &first)->data);
- printf("(if the number returned happens to be different than the number searched for and/or really huge, it means that it couldn't find it. Curse you lack of error checking caused by instructions! *shakes fist*)\n");
- current = first->next;
- while (current)
- {
- free(current);
- current = current->next;
- }
- displayLeaks();
- return 0;
- }
- struct node *searchList(int value, node *head)
- {
- while(head)
- {
- if(value == head->value)
- {
- return head;
- }
- head = head->next;
- }
- return NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement