I'm trying to count the number of each character in the string with using a searching function and adding every time it appears.
Here's my program so far
#include<stdio.h>
int countCharactersCaseSensitive(char *inStr, char);
int main()
{
char ascii[52];
int capital = 65;
int i;
for (i = 0; i <26; i++)
{
ascii[i] = capital;
capital++;
}
int lower = 97;
for (i=26; i< 52; i++)
{
ascii[i] = lower;
lower++;
}
char *str = "Programming Assignment";
int count[52];
for (i=0;i<52;i++)
{
char check = ascii[i];
count[i] = countCharactersCaseSensitive(str,check);
}
for(i=0;i<52;i++)
{
printf("%c%10d\n",ascii[i],count[i]);
}
}
int countCharactersCaseSensitive(char *inStr, char check)
{
int i;
int count = 0;
int length = strlen(inStr);
for (i=0;i<length;i++)
{
if(check == *inStr)
{
inStr++;
count++;
}
}
return count;
}
But it only checks for P, how do i fix this to check the other characters in the string?