Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
BSEARCH() COMPLETE
#include <stdio.h> #include <stdlib.h> #include <ctype.h> typedef struct { char name[101]; unsigned short age; }student; void input(student *, unsigned short ); void strUpper(char *); int compareAge(const void *, const void *); void output(student *, unsigned short); int compare(const void *, const void *); int main(void) { student array[1000]; student *pointer; unsigned short total; unsigned short clave; scanf("%hu", &total); scanf("%hu", &clave); input(array, total); qsort(array, total, sizeof(student), compareAge); output(array, total); pointer = bsearch(&clave, array, total, sizeof(student), compare); if ( pointer == NULL) printf("\n%hu NO ESTA EN EL ARRAY", clave); else { int position = pointer - array; printf("\n%hu ESTA EN EL ARRAY, EN LA POSICION %d", clave, position); } return 0; } void input(student *array, unsigned short total) { unsigned short i; for ( i = 0 ; i < total ; i ++ ) { scanf("%100[^,]s", array[i].name); getchar(); strUpper(array[i].name); scanf("%hu", &array[i].age); } total = i; } void strUpper(char *name) { while ( *name != '\0' ) { if ( islower( *name) ) *name = toupper( *name); name ++; } } int compareAge(const void *pivot, const void *element) { student *ptrPivot = (student *) pivot; student *ptrElement = (student *) element; return ( ptrPivot -> age) - ( ptrElement -> age); } void output(student *array, unsigned short total) { unsigned short i; for ( i = 0 ; i < total ; i ++ ) printf("%s %hu", array[i].name, array[i].age); } int compare(const void *clave, const void *element) { unsigned short *ptrClave = (unsigned short *) clave; student *ptrElement = (student *) element; return *ptrClave - ptrElement -> age; }
run
|
edit
|
history
|
help
0
Memoria dinamica no funciona ;C
Arrays Grtade and Toppers
pth_trap.c
HW2A
WAP in C to print the reverse of a string
pth_monte_carlo_pi.c
18BCE2182 ASSESS_1 Q2-1
A_141110_Perfecto
X=2
MinMaxArray