请问,主函数和被调用函数都可以用指针运算替换数组下标吗?怎么做?
#include// 检查输入的句子是不是回文
#include
#define LEN 100
int compare(const char str[],int n);
int main(void)
{
char ch,str_1[LEN];
int i=0;
printf("Enter a message:");
while((ch=getchar())!='\n')//输入句子
if(toupper(ch)<=90&&toupper(ch)>=65)//是字母就存入数组
str_1[i++]=ch;
if(compare(str_1,i)==1)//调用compare函数,返回1是回文
printf("Plindrome\n");
else if (compare(str_1,i)==0)//调用compare函数,返回0不是回文
printf("Not a Plindrome\n");
return 0;
}
int compare(const char str[],int n)//检测回文的函数。
{
int i=0,a,b,flag;
for(i=0;i<=(n/2)-1;i++){
a=toupper(str[i]);
b=toupper(str[(n-1)-i]);
if(a!=b){
flag=0;
break;
}
else
flag=1;
}
return flag;
}