I'm trying to count how many dashes "-" there are in char p[]. I loop over the string, and use the strcmp function to compare what is at the p[i] location to "-". The strcmp function returns 0 if the they are the same.
int howmanyDash( char p[] ){
int length = strlen(p);
int i, count = 0;
for (i = 0; i < length; i++)
{
if (strcmp(p[i], "-") == 0)
{
++count;
}
}
return count;
}
int main(){
char word[20];
scanf("%s", word);
int dashCount = howManyDash(word);
printf("Dashes: %d\n", dashCount);
return 0;
}
The error I am getting reads as follows: warning: incompatible integer to pointer conversion passing 'char' to parameter of type 'const char *'; take the address with & [-Wint-conversion] if (strcmp(p[i], "-") == 0)
This warning was generated on line 7: if (strcmp(p[i], "-") == 0)