Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PREGUNTA 2, GUÍA 4, MÓDULO 3
#include <stdio.h> #include <ctype.h> #include <string.h> #include <stdlib.h> typedef struct { char mail[321]; char domain[256]; }users; typedef struct { char dominio[256]; unsigned short cantidad; }domains; // -----------------Prototypes---------------------- void findDomain ( char *, char * ); int compareDomains( const void *, const void * ); void lowerCase( char * ); void output( const users *, domains *, int ); int compareFrequency( const void *, const void* ); // ---------------Main Program----------------------- int main(void) { users typeDomain[10000]; domains arrayDominios[10000]; int i = 0; int total; // --------------------------Input---------------------- while ( i < 10000) { scanf("%320s", typeDomain[i].mail); if ( strcmp(typeDomain[i].mail, "FIN") == 0) break; i++; } // -----------------------Process----------------------- total = i; for (i = 0 ; i < total ; i++) findDomain(typeDomain[i].mail, typeDomain[i].domain); for (i = 0 ; i < total ; i++) lowerCase(typeDomain[i].domain); qsort(typeDomain, total, sizeof(users), compareDomains); // ---------------------Output------------------------- output( typeDomain, arrayDominios, total); return 0; } void output( const users *type, domains *array, int total) { short i; short j = 0; unsigned short sum = 1; int cant = 0; for (i = 0 ; i < total ; i++) { if ( strcmp( type[i].domain, type[i + 1].domain) == 0) sum ++; else { strcpy(array[j].dominio, type[i].domain); array[j].cantidad = sum; sum = 1; cant ++; j ++; } } total = cant; qsort(array, total, sizeof(domains), compareFrequency); printf("DOMINIOS DIFERENTES ENCONTRADOS\n"); printf("===============================\n"); for (i = 0 ; i < total ; i++) printf("%s %hu\n", array[i].dominio, array[i].cantidad ); } /* -------------------------Procedimiento findDomain------------------------------- * Propósito: encontrar el dominio de un correo electrónico. Ejemplo: * pedro@hotmail.com, el dominio es: hotmail.com * */ void findDomain ( char *mail, char *domain) { char *pointer; pointer = mail; pointer = strchr(mail, '@'); strcpy(domain, pointer + 1); } int compareDomains( const void *pivot, const void *element ) { users *ptrPivot = (users *) pivot; users *ptrElement = (users *) element; return strcmp( ( ptrPivot -> domain ), ( ptrElement -> domain ) ); } int compareFrequency( const void *pivot, const void *element ) { domains *ptrPivot = (domains *) pivot; domains *ptrElement = (domains *) element; return (ptrElement -> cantidad) - (ptrPivot -> cantidad); } /* -------------------------Procedimiento lowerCase------------------------------- * Propósito: En caso de que un dominio este escrito en mayúscula, el procedimiento transformara el dominio a minúscula. * ejemplo: GMAIL.COM -------> gmail.com * Argumento: dominio. */ void lowerCase( char *domain) { while ( *domain != '\0') { if ( isupper( *domain ) ) *domain = tolower(*domain); domain ++; } }
run
|
edit
|
history
|
help
0
fibonacci1
pseudo hw v.05
My first reevers C 2darryp
b=1 c=1
double_buffer_madness
Búsqueda binaria rec
150109_RecursividadPrimo
Conditional logic.c
Lab 8 part 2 v.05
Max of arrays