Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
CONTADOR DE PALABRAS
typedef struct word{ char word[41]; int quantity; } word; bool isaword (char *sentence){ int i=0; for(i=0; sentence[i]!='\0';i++){ if(isalpha(sentence[i])){ } else{ return false ; } } return true; } void lowercase (char *sentence){ int i=0; for(i=0; sentence[i]!='\0';i++){ sentence[i]=tolower(sentence[i]); } } // INICIO FUNCION PARA OCUPAR QSORT int compareQSORT (const void *A, const void *B){ word *ptrA =(word*) A; word *ptrB =(word*) B; return strcmp((ptrB->word),(ptrA->word)); } // FIN FUNCION PARA OCUPAR QSORT int comparewords(char *sentence, int quan,word *vectorword ){ for(int i=0;i<quan;i++){ if(strcmp(sentence,vectorword[i].word)==0){ return i; } } return -1; } void mostrarPalabrasFrecuencia(FILE *entrada,FILE **salida){ word *vectorword=NULL; char sentence[100]; int n=0; int cant=0; while((fscanf(entrada,"%s",sentence))!=EOF){ if(isaword(sentence)==true){ lowercase(sentence); if((cant>=1)&&comparewords(sentence,cant,vectorword)!=-1){ vectorword[comparewords(sentence,cant,vectorword)].quantity++; } else{ vectorword=realloc(vectorword,sizeof(word)*(n+1)); int i; for(i=0;sentence[i]!='\0';i++){ vectorword[n].word[i]=sentence[i]; } vectorword[n].word[i]='\0'; vectorword[n].quantity=1; cant++; n++; } } } qsort(vectorword,cant,sizeof(word),compareQSORT); for(int i=cant-1;i>=0;i--){ fprintf(*salida,"%s %d\n",vectorword[i].word,vectorword[i].quantity); } }
run
|
edit
|
history
|
help
0
Euclides MIRAR
Media de 3 numeros
LECTURA DE CADENAS CON FGETS
gcc compiler bug.. weird.
22nd HW Switchv0.24
Arrays Grtade and Toppers
PUNTEROS 1
Shapes and such
A_141107_Potencia
Refcount220323