Code:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define MAX_CHAR 256
void get_vowels(char s[]) //, int *a, int *e, int *i, int *o, int *u)
{
//int vowels [5] = {'a','e','i','o','u'};
int alpha[26] = {'a','b','c','d','e','f','g','h','i','j','k','l',
'm','n','o','p','q','r','s','t','u','v','w','x','y','z'};
int alpha_count [ 26 ] = { 0 };
int hold_postion [ 1 ] = { 0 }; // only needs to be one element it is only keeping one value,
// so is an array here really needed for what you are using it for?
int max = 0; // you where stuck on sorting that array which is not needed so this is what you need here
// int A = 0, E =0, I=0,O=0,U=0;
int len; //, count = 0;
int x = 0, b = 0;
len = strlen(s);
// your set up for your nested while loops was almost correct.
// so I just used this to show you what you're doing wrong.
while (x < len)
{
b = 0;
while(b < 26)
{
if( tolower( s[x]) == alpha[b])
{
alpha_count[b]++;
}
b++;
}
x++;
}
for ( int i = 0 ; i < 26; i++)
printf("letter is %c was used %d times\n",alpha[i], alpha_count[i] );
// now you will have the total amount of letters max count for each letter in your
// alpha_count array, that the element match up to your alpha array
//now all you have to do is find the max ( greatest value out of all 26 elements)
for (int j = 0; j < 26; j++)
if ( alpha_count [ j ] > max )
{
// two lines of code here needed to update
// two separate things
// the printf will give you a clue to one of them
// because you were already doing that one anyhow
/// enjoy
}
printf("letter %c is most times counted, being %d times\n", alpha[hold_postion[0] ], alpha_count[hold_postion[0] ]);
}
int main (void)
{
char sentence[MAX_CHAR];
printf("Enter a sentence \n");
fgets(sentence, MAX_CHAR, stdin);
get_vowels(sentence); //, &a, &e, &i, &o, &u);
return 0;
}
it looked like you were missing a bunch of your code because I could not get it running , so I just used this as your while loops were almost right, how you were getting your input was not present so I had to improvise and do as stated modify existing code .. reuse of code is a 21st century thing ya know