Search code examples
c++cstrcmp

strcmpi integer without a cast error


I'm trying to create a program that removes vowels from a string, add them into a vector and then give the user the possibility of having the original code again.

In my code i have this:

char s[20];

And soon after i have this comparison:

for(j=0;j<tam;j++)
{
    if(strcmpi(s[j],"a")==1 ||
       (strcmpi(s[j],"e")==1 ||
       (strcmpi(s[j],"i") ==1||
       (strcmpi(s[j],"o") ==1||
       (strcmpi(s[j],"u")==1))
    {

So if the array is char and the vowels are char(""), why the compiler give me this error?:

[Warning] passing arg 1 of `strcmpi' makes pointer from integer without a cast

EDIT
As someone said the correct is s[j] == 'a', but that result in wrong way. If a put car the result is still car. Don't know why.

 if(s[j] == 'a' || 
    s[j] == 'A' || 
    s[j] == 'e' || 
    s[j] == 'E' || 
    s[j] == 'i' || 
    s[j] == 'I' || 
    s[j] == 'o' || 
    s[j] == 'O' || 
    s[j] == 'u' || 
    s[j] == 'U') 
 {
    s[j] = s[j++]; }

Solution

  • Strcmpi is for comparing strings. The first argument to strcmpi is of type char, when it expects a char*.

    In order to compare single chars, s[j]=='e' is enough, or tolower(s[j])=='e' if you need it to be case insensitive. You'll need to include ctype.h. for tolower.