Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
etapa final de pregunta 2
#include <stdio.h> #include <ctype.h> #include <string.h> #include <stdlib.h> typedef struct { char mail[321]; char domain[256]; }domains; // -----------------Prototypes---------------------- void findDomain ( char *, char *); int compareDomains( const void *, const void * ); void lowerCase( char *); // ---------------Main Program----------------------- int main(void) { domains typeDomain[10000]; int i = 0, j; int total; unsigned short sum; // --------------------------Input---------------------- while ( i < 10000) { scanf("%320s", typeDomain[i].mail); if ( strcmp(typeDomain[i].mail, "FIN") == 0) break; i++; } // -----------------------Process----------------------- total = i; //printf("total: %d.\n\n", total); for (i = 0 ; i < total ; i++) findDomain(typeDomain[i].mail, typeDomain[i].domain); for (i = 0 ; i < total ; i++) lowerCase(typeDomain[i].domain); /* for (i = 0 ; i < total ; i++) printf("%s\n", typeDomain[i].domain);*/ qsort(typeDomain, total, sizeof(domains), compareDomains); printf("\nDOMINIOS ORDENADOS\n\n"); for (i = 0 ; i < total ; i++) printf("%s\n", typeDomain[i].domain); printf("DOMINIOS DIFERENTES ENCONTRADOS\n"); printf("===============================\n"); for (i = 0 ; i < total - 1 ; i++) { sum = 1; for (j = i + 1 ; j < total ; j++) { if ( strcmp(typeDomain[i].domain, typeDomain[j].domain) == 0 ) sum ++; else break; } printf("%s %hu\n", typeDomain[i].domain, sum); i = j - 1; } return 0; } /* -------------------------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 ) { domains *ptrPivot = (domains *) pivot; domains *ptrElement = (domains *) element; return strcmp( ( ptrPivot -> domain ), ( ptrElement -> domain ) ); } void lowerCase( char *domain) { while ( *domain != '\0') { if ( isupper( *domain ) ) *domain = tolower(*domain); domain ++; } }
run
|
edit
|
history
|
help
0
C_141120_factorial02
sphere
ECE 2574 1/23
A_141117_Euclides
HeapSort
union behaviour when const obj created
3.1.3 Quick sort, Merge sort
Basic String Compression in C
C_141203_PALINDROMO
ele709 lab 3.2