so far the programming i have finds the percentage at which the letters occur however i need help finding the first and second most frequent that occur the code was from a book with a little modification i know i need to use a bubble sort but im having trouble understanding them
heres what i have:
Code:
#include <stdio.h>
#include <string.h>
void getthestring(char string[]);
void countcharacters(char string[],int array[],int length);
void fixcase(char string[]);
void initialize(int array[], int numberelements);
main()
{
char
mystring[500];
int
countarray[26],x[26],i,j,k,length,max,sec;
initialize(countarray,26);
getthestring(mystring);
length = strlen(mystring);
printf("\nyou entered %d characters \n\n",length);
fixcase(mystring);
countcharacters(mystring,countarray,length);
for(i=0;i<26;i=i+1)
{
printf("%c %5.2f \% ",i+97,((countarray[i]*100.0)/length));
if ((i+1)%5 == 0)
printf("\n");
}
printf("\n");
getchar();
getchar();
}
void getthestring(char string[])
{
printf("please enter a sentence,up to 500 characters long\n\n");
gets(string);
}
void countcharacters(char string[],int array[],int length)
{
int
i,j;
for(i=0;i<length;i=i+1)
for(j=97;j<123;j=j+1)
if(string[i] == j)
{
array[j-97] = array[j-97] + 1;
j=123;
}
}
void fixcase(char string[])
{
int
i=0;
while(string[i] != '\0')
{
if((string[i] >= 65) && (string[i] <=90))
string[i] = string[i] + 32;
i = i + 1;
}
}
void initialize(int array[], int numberelements)
{
int
i;
for(i=0;i<numberelements;i = i + 1)
array[i] = 0;
}
i have 3 variables unused at all because my profesor said to use them to bubble sort for the most frequent letters in the array and to set x[26] = countarray[26] max is the first letter sec is the 2nd most occuring the he also said use for(i=0;i<26;i++) and if(countarray[i]==x) something similar to that,max=x[0] and max[1] and prinf to show the results
where do i place this stuff though?