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