帮忙看一下这段C程序

来源:百度知道 编辑:UC知道 时间:2024/05/05 17:22:21
#include <stdio.h>
#include <math.h>
#include <string.h>

int judge(char a[],int len){

char *p1=a,*p2=&a[len-1]; //指针p1指向数组首地址,p2指向数组结束位置
int q=len/2; //循环终止位置
for(int b=1;b<=q;p1++,p2--){ //循环p1加,p2减
if(*p1!=*p2){ //不相等则返回0,结束循环
return 0;
}
b++;
return 1;
}
}

void main(){
char str[20];
printf("input a string:");
scanf("%s",str);
int a;
a=strlen(str);
printf("%d\n",judge(str,a));
}

是判断回文数的,用指针做的,虽然能运行,但是警告里说 不是所有的路径都有返回值。各位大侠帮忙看一下,谢谢啦!!!
为什么呢?有什么区别吗?如果把return 1写在for 循环外面的话岂不是永远都return1了···

是否应该把return写在那个for的大括号的外面

#include <stdio.h>
#include <math.h>
#include <string.h>

int judge(char a[],int len){

char *p1=a,*p2=&a[len-1]; //指针p1指向数组首地址,p2指向数组结束位置
int q=len/2; //循环终止位置
for(int b=1;b<=q;p1++,p2--){ //循环p1加,p2减
if(*p1!=*p2){ //不相等则返回0,结束循环
return 0;
}
b++;
}
return 1;

}

void main(){
char str[20];
printf("input a string:");
scanf("%s",str);
int a;
a=strlen(str);
printf("%d\n",judge(str,a));
}

好像你程序写错了。
///////////////////////////////
for(int b=1;b<=q;p1++,p2--){ //循环p1加,p2减
if(*p1!=*p2){ //不相等则返回0,结束循环
return 0;
}
b++;
return 1;
}
////////////////////////////////////
上面的return 1; 应该放在 } 后面,即:
b++;
}
return 1;
////////////////////////////////////

int judge(char a[],int len){

c