Do help me on this. I'm trying to create a function where the user can input 10 alphabets and the characters will be saved in a array iterated with a for loop. But, I'm having problems with passing the arrays.
#include <stdio.h>
#include <conio.h>
void listAlpha( char ch)
{
printf(" %c", ch);
}
int readAlpha(){
char arr[10];
int count = 1, iterator = 0, result;
for(int iterator=0; iterator<10; iterator++){
printf("\nAlphabet %d:", count);
scanf(" %c", &arr[iterator]);
count++;
}
printf("\n-----------------------------------------");
printf("\nList of alphabets: ");
for (int x=0; x<10; x++)
{
/* I’m passing each element one by one using subscript*/
listAlpha(arr[x]);
}
result = findTotal(arr);
return 0;
}
int findTotal(char arr[]){
int alpha_a , alpha_b , alpha_c;
for(int a = 0; a < 10; a++){
if(arr[a] == "A" || "a"){
alpha_a + 1;
}
else if(arr[a] == "B"){
alpha_b + 1;
}
else if(arr[a] == "C"){
alpha_c + 1;
}
}
printf("\nTotal alphabet A: %d", alpha_a);
printf("\nTotal alphabet B: %d", alpha_b);
printf("\nTotal alphabet C: %d", alpha_c);
}
int main(){
readAlpha();
}
I'm trying to pass the array arr[iterator] into findTotal() to count and display the total number of alphabet inputted. Moreover, I shall also have to find the result of the highest number of alphabets entered in the main() function.
The output should look something like this.
Alphabet 1: A
Alphabet 2: B
Alphabet 3: C
Alphabet 4: A
Alphabet 5: B
Alphabet 6: C
Alphabet 7: A
Alphabet 8: B
Alphabet 9: C
Alphabet 10: A
---------------------------------------------------------------------------------
List of alphabets: A B C A B C A B C A
Total alphabet A: 4
Total alphabet B: 3
Total alphabet C: 3
The highest number of alphabets is A.