I have an array of size 25 that stores capital letters in an array. It stores, for my user input test, 'A', 'B', 'C', and 'D'. My program counts the amount of those letters in the array and prints it out. For example, if AABBCCDD was entered, it would say there are 2 A's, 2 B's, 2 C's and 2 D's. Now, I am trying to get it to accept lower case letters as well and count them as long as they are the same as the uppercase. For example, if I entered, aA,Bb, cC and dD, it would still print that there are two of each. MY code is the following:
int main(void)
{
char array[25];
printf("Enter array: \n");
scanf("%[^\n]", array);
printf(Array is: ", array);
count(array, 'A');
return 0;
}
void count(char* array, char p)
{
int i, count = 0;
for (i = 0; array[i] !='\0'; i++)
if(array[i] == p)
count++;
printf("Number of %c's: %d\n, p, count);
}
I want the code to count both 'a' and 'A'. Is using toupper() the approach?