gpt4 book ai didi

我的 Anagram 程序可以运行吗?如果是,为什么不编译?

转载 作者:行者123 更新时间:2023-11-30 21:28:55 25 4
gpt4 key购买 nike

我的程序无法编译。它不断地说:[错误]从“char”到“char*”的转换无效它应该是一个识别两个字符串是否是彼此的字谜的程序。我使用了排序方法,但我不知道它是否有效。希望你们能帮助我。P.S 我只能使用字符串和数组。

int main ()
{
char sString_1[100], sString2[100], store[50];
int j, i;

printf("Enter String 1: ");
gets(sString_1);
printf("\nEnter String 2: ");
gets(sString2);

if (strlen(sString_1) != strlen(sString2))
printf("%s and %s are not anagrams", sString_1, sString2);
else
{
for(i = 0; i < strlen(sString_1); ++i)
{
for (j=i+1 ; j <= strlen(sString_1); ++j)
{
if (strcmp(sString_1[i], sString2[j]) > 0)
{
strcpy(store,sString_1[i]);
strcpy(sString_1[i],sString_1[j]);
strcpy(sString_1[j],store);
}

}
}

for(i = 0; i < strlen(sString2); i++)
{
for (j= i + 1; j <= strlen(sString2); j++)
{
if (strcmp(sString2[i], sString2[j]) >0)
{
strcpy(store,sString2[i]);
strcpy(sString2[i],sString2[j]);
strcpy(sString2[j],store);
}
}
}

if (strcmp(sString_1, sString2) == 0)
printf("ANAGRAM");
else
printf("NOT");
}
}

最佳答案

strcmp(sString_1[i], sString2[j])

strcmp 的参数应为 const char * 类型,但您传递的是单个字符。

关于我的 Anagram 程序可以运行吗?如果是,为什么不编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36720872/

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