.\" -*- coding: UTF-8 -*- .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\" References consulted: .\" Linux libc source code .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) .\" 386BSD man pages .\" .\" Modified 1993-03-29, David Metcalfe .\" Modified 1993-07-24, Rik Faith (faith@cs.unc.edu) .\" 2006-01-15, mtk, Added example program. .\" Modified 2012-03-08, Mark R. Bannister .\" and Ben Bacarisse .\" Document qsort_r() .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH QSORT 3 "1 Noviembre 2020" "" "Manual del Programador de Linux" .SH NOMBRE qsort, qsort_r \- ordena un vector .SH SINOPSIS .nf \fB#include \fP .PP \fBvoid qsort(void *\fP\fIbase\fP\fB, size_t \fP\fInmemb\fP\fB, size_t \fP\fIsize\fP\fB,\fP \fB int (*\fP\fIcompar\fP\fB)(const void *, const void *));\fP .PP \fBvoid qsort_r(void *\fP\fIbase\fP\fB, size_t \fP\fInmemb\fP\fB, size_t \fP\fIsize\fP\fB,\fP \fB int (*\fP\fIcompar\fP\fB)(const void *, const void *, void *),\fP \fB void *\fP\fIarg\fP\fB);\fP .fi .PP .RS -4 Requisitos de Macros de Prueba de Características para glibc (véase \fBfeature_test_macros\fP(7)): .RE .PP .ad l \fBqsort_r\fP(): _GNU_SOURCE .ad b .SH DESCRIPCIÓN La función \fBqsort\fP() ordena un vector de \fInmiemb\fP elementos de tamaño \fItam\fP. El argumento \fIbase\fP apunta al comienzo del vector. .PP Los contenidos del vector se clasifican en orden ascendente de acuerdo a una función de comparación a la que apunta \fIcompar\fP, que se llama con dos argumentos que apuntan a los objetos a comparar. .PP La función de comparación debe devolver un entero menor que, igual a, o mayor que cero si el primer argumento se considera respectivamente menor, igual o mayor que el segundo. Si dos miembros se comparan como iguales, su orden en el vector clasificado queda indefinido. .PP The \fBqsort_r\fP() function is identical to \fBqsort\fP() except that the comparison function \fIcompar\fP takes a third argument. A pointer is passed to the comparison function via \fIarg\fP. In this way, the comparison function does not need to use global variables to pass through arbitrary arguments, and is therefore reentrant and safe to use in threads. .SH "VALOR DEVUELTO" The \fBqsort\fP() and \fBqsort_r\fP() functions return no value. .SH VERSIONES \fBqsort_r\fP() was added to glibc in version 2.8. .SH ATRIBUTOS Para obtener una explicación de los términos usados en esta sección, véase \fBattributes\fP(7). .TS allbox; lbw18 lb lb l l l. Interfaz Atributo Valor T{ \fBqsort\fP(), \fBqsort_r\fP() T} Seguridad del hilo Multi\-hilo seguro .TE .sp 1 .SH "CONFORME A" \fBqsort\fP(): POSIX.1\-2001, POSIX.1\-2008, C89, C99, SVr4, 4.3BSD. .SH NOTAS To compare C strings, the comparison function can call \fBstrcmp\fP(3), as shown in the example below. .SH EJEMPLOS For one example of use, see the example under \fBbsearch\fP(3). .PP Another example is the following program, which sorts the strings given in its command\-line arguments: .PP .EX #include #include #include static int cmpstringp(const void *p1, const void *p2) { /* The actual arguments to this function are "pointers to pointers to char", but strcmp(3) arguments are "pointers to char", hence the following cast plus dereference */ return strcmp(*(const char **) p1, *(const char **) p2); } int main(int argc, char *argv[]) { if (argc < 2) { fprintf(stderr, "Usage: %s ...\en", argv[0]); exit(EXIT_FAILURE); } qsort(&argv[1], argc \- 1, sizeof(char *), cmpstringp); for (int j = 1; j < argc; j++) puts(argv[j]); exit(EXIT_SUCCESS); } .EE .SH "VÉASE TAMBIÉN" \fBsort\fP(1), \fBalphasort\fP(3), \fBstrcmp\fP(3), \fBversionsort\fP(3) .SH COLOFÓN Esta página es parte de la versión 5.10 del proyecto Linux \fIman\-pages\fP. Puede encontrar una descripción del proyecto, información sobre cómo informar errores y la última versión de esta página en \%https://www.kernel.org/doc/man\-pages/. .SH TRADUCCIÓN La traducción al español de esta página del manual fue creada por Gerardo Aburruzaga García . Esta traducción es documentación libre; lea la .UR https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 .UE o posterior con respecto a las condiciones de copyright. No existe NINGUNA RESPONSABILIDAD. Si encuentra algún error en la traducción de esta página del manual, envíe un correo electrónico a .MT debian-l10n-spanish@lists.debian.org>. .ME .