.\" -*- coding: UTF-8 -*- '\" t .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .\" 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 "20 ​​Julio 2023" "Páginas de manual de Linux 6.05.01" .SH NOMBRE qsort, qsort_r \- ordena un vector .SH BIBLIOTECA Biblioteca Estándar C (\fIlibc\fP, \fI\-lc\fP) .SH SINOPSIS .nf \fB#include \fP .PP \fBvoid qsort(void \fP\fIbase\fP\fB[.\fP\fIsize\fP\fB * .\fP\fInmemb\fP\fB], size_t \fP\fInmemb\fP\fB, size_t \fP\fIsize\fP\fB,\fP \fB int (*\fP\fIcompar\fP\fB)(const void [.\fP\fIsize\fP\fB], const void [.\fP\fIsize\fP\fB]));\fP \fBvoid qsort_r(void \fP\fIbase\fP\fB[.\fP\fIsize\fP\fB * .\fP\fInmemb\fP\fB], size_t \fP\fInmemb\fP\fB, size_t \fP\fIsize\fP\fB,\fP \fB int (*\fP\fIcompar\fP\fB)(const void [.\fP\fIsize\fP\fB], const void [.\fP\fIsize\fP\fB], 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 \fBqsort_r\fP(): .nf _GNU_SOURCE .fi .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" La función \fBqsort\fP() y \fBqsort_r\fP() no devuelven nada. .SH ATRIBUTOS Para obtener una explicación de los términos usados en esta sección, véase \fBattributes\fP(7). .TS allbox; lbx lb lb l l l. Interfaz Atributo Valor T{ .na .nh \fBqsort\fP(), \fBqsort_r\fP() T} Seguridad del hilo Multi\-hilo seguro .TE .sp 1 .SH ESTÁNDARES .TP \fBqsort\fP() C11, POSIX.1\-2008. .SH HISTORIAL .TP \fBqsort\fP() POSIX.1\-2001, C89, SVr4, 4.3BSD. .TP \fBqsort_r\fP() glibc 2.8. .SH NOTAS Para comparar cadenas de C, la función que la realiza puede invocar la llamada \fBstrcmp\fP(3) tal como se muestra en el siguiente ejemplo. .SH EJEMPLOS Un buen ejemplo sería el que ilustra \fBsearch\fP(3). .PP Another example is the following program, which sorts the strings given in its command\-line arguments: .PP .\" SRC BEGIN (qsort.c) .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 (size_t j = 1; j < argc; j++) puts(argv[j]); exit(EXIT_SUCCESS); } .EE .\" SRC END .SH "VÉASE TAMBIÉN" \fBsort\fP(1), \fBalphasort\fP(3), \fBstrcmp\fP(3), \fBversionsort\fP(3) .PP .SH TRADUCCIÓN La traducción al español de esta página del manual fue creada por Gerardo Aburruzaga García y Marcos Fouces . .PP 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. .PP 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 .