Lulusawrs
Lulusawrs

Reputation: 9

"expected 'char *' but argument is of type 'char' " - palindrom + reverse

Right now this program succesfully reverses a word typed in by the keyboard. But I want to "save" the word in the pointer before I reverse it, so I can compare both, the reversed one and the "original", and check if they are palindromes. I don't have much experience yet and there might be more errors than I know of, but I can't find a solution.

#include <stdio.h>
#include <string.h>

void reverse(char s[])
{
    int c,i,j;
    for(i=0, j=strlen(s)-1; i<j; i++, j--)
    {
        c = s[i];
        s[i] = s[j];
        s[j] = c;
    }

}

void Palindromcheck(char u[], char g[])
{
    if(u == g)
    {
        printf("Word \"%s\" is a palindrom\n", g);
    }
    else
    {
        printf("Word \"%s\" is not a Palindrom\n", g);
    }
}
int main()
{
    char c[30];
    printf("Please enter a value \n");
    scanf("%s", c);
    char *ptr1 = c;
    printf("String: %s\n", c);
    reverse(c);
    printf("%s\n", c);
    Palindromcheck(c, *ptr1);
    return 0;
}

I get two warnings saying:

expected 'char *' but argument is of type 'char'

at the function palindromcheck itself, such as:

passing argument 2 of 'palindromcheck' makes pointer from integer without a cast [-Wint-conversion]

at the function call.

Appreciate any help:)

Upvotes: 0

Views: 1754

Answers (1)

grapes
grapes

Reputation: 8646

Toy need to change this

Palindromcheck(c, *ptr1);

to this

Palindromcheck(c, ptr1);

Function expects pointer to char, as parameter is char g[], and you are trying to pass just char value.

Upvotes: 4

Related Questions