c - "expected ' 字符 * ' but argument is of type ' 字符 ' "- 回文 + 反向

标签 c string char palindrome

现在这个程序成功地反转了键盘输入的单词。但是我想在我反转它之前“保存”指针中的单词,所以我可以比较两者,反转的和“原始的”,并检查它们是否是回文。我还没有太多经验,可能会出现比我知道的更多的错误,但我找不到解决方案。

#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;
}

我收到两条警告:

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

在函数palindromcheck本身,例如:

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

在函数调用处。

感谢任何帮助:)

最佳答案

玩具需要改变这个

Palindromcheck(c, *ptr1);

对此

Palindromcheck(c, ptr1);

函数需要指向 char 的指针,因为参数是 char g[],而您正试图传递 char 值。

关于c - "expected ' 字符 * ' but argument is of type ' 字符 ' "- 回文 + 反向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53539956/

相关文章:

代码给我一个无限循环

C 字符串数组顺序操作

在 32 位 CentOS (RHEL) 6 上交叉构建 64 位用户空间程序

java - 使用指定分隔符拆分字符串,不遗漏空元素

c - 如何修复多字符常量警告

c - 将 char 字符串解析为 INT C 编程

c# - PInvoke 使堆栈不平衡

java - 用正则表达式分割许多单个字符(java)

javascript - JavaScript声明一个变量并在一个语句中使用逗号运算符?

c - 为什么下面的 C 代码在 int 45 的情况下打印 45,在 STRING 的情况下打印 36,而 CHAR 的 ASCII 值则打印 36?