-
Notifications
You must be signed in to change notification settings - Fork 0
/
program10-10.c
51 lines (37 loc) · 887 Bytes
/
program10-10.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Returning a Pointer from a Function
#include <stdio.h>
struct entry
{
int value;
struct entry *next;
};
struct entry *findEntry(struct entry *listPtr, int match)
{
while (listPtr != (struct entry *) 0)
if (listPtr->value == match)
return (listPtr);
else
listPtr = listPtr->next;
return (struct entry *) 0;
}
int main(void)
{
struct entry *findEntry(struct entry *listPtr, int match);
struct entry n1, n2, n3;
struct entry *listPtr, *listStart = &n1;
int search;
n1.value = 100;
n1.next = &n2;
n2.value = 200;
n2.next = &n3;
n3.value = 300;
n3.next = 0;
printf("Enter value to locate: ");
scanf("%i", &search);
listPtr = findEntry(listStart, search);
if (listPtr != (struct entry *) 0)
printf("Found %i.\n", listPtr->value);
else
printf("Not found.\n");
return 0;
}