gpt4 book ai didi

c - 该函数不能返回 int 值

转载 作者:太空宇宙 更新时间:2023-11-04 02:17:15 25 4
gpt4 key购买 nike

int sum_s1=0, sum_s2=0;

int comps(char s1[], char s2[]) {

if (s1[0] == '\0' && s2[0] == '\0') {

if (sum_s1 == sum_s2) {
printf("hihi"); //printable
return 1; //return the 4202692

} else {
return 0;
}

} else {

if (*s1 != '\0') {

if (s1[0]!=32) {
sum_s1 += s1[0];

} else {
sum_s1 += 0;

}
*s1 = *(s1+1);
}
if (*s2 != '\0') {

if (s2[0]!=32) {
sum_s2 += s2[0];

} else {
sum_s2 += 0;

}

*s2 = *(s2+1);
}

if (*s1 != '\0' && *s2 == '\0') equalIgnoreSpace(s1+1, "\0");
if (*s1 == '\0' && *s2 != '\0') equalIgnoreSpace("\0", s2+1);
if (*s1 != '\0' && *s2 != '\0') equalIgnoreSpace(s1+1, s2+1);
if (*s1 == '\0' && *s2 == '\0') equalIgnoreSpace("\0", "\0");
}
}

int main() {

int compa=1;


compa = comps("abc f", "abcf");
printf("%d", compa); //return the 4202692


if (compa == 1) {
printf("Two string are equal");
} else {
printf("Two string are not equal");
}

getchar();
return 0;
}

comps() 应该返回 1 并停止,但我无法在 main 函数中获取 1。我该如何解决这个问题?

最佳答案

comps函数中没有return语句[in else case]

int comps(char s1[], char s2[]) 
{
if (s1[0] == '\0' && s2[0] == '\0')
{
if (sum_s1 == sum_s2)
{
printf("hihi"); //printable
return 1; //return the 4202692
}
else
return 0;
}
else
{
...
...
return code;
}
}

关于c - 该函数不能返回 int 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5762430/

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