Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
BSEARCH() WITH STRUCT
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
#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); pointer = bsearch(&clave, array, total, sizeof(student), compare); if ( pointer == NULL) printf("%hu NO ESTA EN EL ARRAY", clave); else printf("%hu ESTA EN EL ARRAY", clave); //output(array, total); 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; }
gcc
3 20 manuel fernando encina,25 carlos encina,21 valeska mateluna,20
Show compiler warnings
[
+
] Compiler args
[
-
]
Show input
Compilation time: 0.24 sec, absolute running time: 0.11 sec, cpu time: 0.04 sec, memory peak: 3 Mb, absolute service time: 0,36 sec
edit mode
|
history
|
discussion
20 ESTA EN EL ARRAY