gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 06:12:28 27 4
gpt4 key购买 nike

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

#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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com