FreeBSD Bugzilla – Attachment 132689 Details for
Bug 177025
[PATCH] lsearch.3 manual page example addition
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
file.diff
file.diff (text/plain), 1.04 KB, created by
Fernando ApesteguĂa
on 2013-03-16 17:40:01 UTC
(
hide
)
Description:
file.diff
Filename:
MIME Type:
Creator:
Fernando ApesteguĂa
Created:
2013-03-16 17:40:01 UTC
Size:
1.04 KB
patch
obsolete
>--- /usr/src/lib/libc/stdlib/lsearch.3 2012-01-03 04:26:05.000000000 +0100 >+++ lsearch.3 2013-03-15 20:27:22.000000000 +0100 >@@ -81,6 +81,49 @@ > Both functions return > .Dv NULL > if an error occurs. >+.Sh EXAMPLES >+.Bd -literal >+ >+#include <search.h> >+#include <stdio.h> >+#include <stdlib.h> >+ >+static int >+element_compare(const void *p1, const void *p2) >+{ >+ int left = *(const int *)p1; >+ int right = *(const int *)p2; >+ >+ return (left - right); >+} >+ >+int >+main(int argc, char **argv) >+{ >+ const int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; >+ size_t element_size = sizeof(array[0]); >+ size_t array_size = sizeof(array) / element_size; >+ int key; >+ void *element; >+ >+ printf("Enter a number: "); >+ if (scanf("%d", &key) != 1) { >+ printf("Bad input\n"); >+ return (EXIT_FAILURE); >+ } >+ >+ element = lfind (&key, array, &array_size, element_size, element_compare); >+ >+ if (element != NULL) >+ printf("Element found: %d\n", *(int *)element); >+ else >+ printf("Element not found\n"); >+ >+ return (EXIT_SUCCESS); >+} >+ >+ >+.Ed > .Sh SEE ALSO > .Xr bsearch 3 , > .Xr hsearch 3 ,
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 177025
: 132689