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
MÓDULO 3, PREGUNTA 1, GUÍA 4
TopLeftTriangle.c
lab pro v.05
B_141202_CADENA_NUMERO
Pointer
Función quicksort para strings
Finding power using recursion
alphabet2 pyramid right
swap_talent.c
Command Expressions in Gnu C: What Does Return Return?