Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
qsort para struct
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct { char nombre[31]; int edad; } tipoPersona; int comparar(const void *pivote, const void *elemento) { tipoPersona *ptrPivote = (tipoPersona *) pivote; tipoPersona *ptrElemento = (tipoPersona *) elemento; if (strcmp(ptrPivote->nombre,ptrElemento->nombre) > 0) return 1; else return 0; } int main(void) { tipoPersona vector[5] = {{"JUAN",18},{"ANA",21},{"PEDRO",23},{"LUIS",19},{"WALTER",22}}; size_t i ; for (i = 0 ; i < 5 ; i++) printf("%s - %d\n",vector[i].nombre,vector[i].edad); qsort(vector,5,sizeof(tipoPersona),comparar); printf("============================\n"); for (i = 0 ; i < 5 ; i++) printf("%s - %d\n",vector[i].nombre,vector[i].edad); return 0; }
run
|
edit
|
history
|
help
0
C list
A_141124Burbuja
Conflito entre 4 threads
some_tests
EXercice
dcl
abc
B_141104_NotaInterroganteDosPuntos
22nd HW Switchv0.1
Program to calculate characters