warning C4715: 'hui' : not all control paths return a value

来源:百度知道 编辑:UC知道 时间:2024/06/28 13:25:28
#include <stdio.h>
#include <string.h>
int hui(char *s)
{
int i,j;
i=0;j=strlen(s)-1;
while(i<j)
{
if(s[i]==s[j]){++i;--j;}
else return 0;
}
if(i>=j) return 1;
}
void main()
{
char s[80];
printf("输入字符串:");
gets(s);
if(hui(s)) puts("是回文");
else puts("不是回文");
}
为什么会出现D:\3.c(13) : warning C4715: 'hui' : not all control paths return a value 要怎么改?

if(i>=j) return 1;

改成 return 1;

#include <stdio.h>
#include <string.h>
int hui(char *s)
{
int i,j;
i=0;j=strlen(s)-1;
while(i<j)
{
if(s[i]==s[j]){++i;--j;}
else return 0;
}
//if(i>=j) return 1;
return 0;
}
void main()
{
char s[80];
printf("输入字符串:");
char *p=gets(s); //我的编译器显示,直接gets(s);这样使用不安全
if(hui(s)) puts("是回文");
else puts("不是回文");
}