I have to allow a user to input a character. The user then inputs a string and the function is to count the amount of time the character appears in the string. I have produced a user-defined function which points to the main function. However, it's not complier is giving coding error in the 'if' function part. Can someone help with the correction. Thanks in advance.
Code:
#include <stdio.h>
#include <string.h>
int strFind(char ch, char *str)
{
int i, n=0;
for(i=0; i<strlen(str); i++){
if(str == ch){
n++;}
else{
}
}
}
int main()
{
char ch, str[100];
printf("Please enter a single character: ");
scanf("%c", &ch);
printf("Please enter a string: ");
scanf("%s", &str);
strFind(ch, *str);
printf("The number of '%c' in '%s' is %d", ch, str, n);
scanf("%d");
return 0;
}