Write a function that accepts a pointer to a string and a character and returns the number of times the character is found in the string.
# include <stdio.h>
# include <conio.h>
# include <string.h>
# include <stdlib.h>
void countletter(char *str);
int main()
{
char str;
printf("Please enter a string: ");
gets(str);
countletter(str);
getch();
return 0;
}
void countletter(char *str)
{
int count;
char a;
gets(a);
for (;(*str)!='\0';str++)
{
if (*str==a)
{
count++;
}
}
printf("%d",count);
}
The error im getting is
error C2664: 'gets' : cannot convert parameter 1 from 'char' to 'char *'
I tried everything to get this. But if anyone has any other ways or writing it i would love to see it. Thanks