检查字符串是否为回文

问题描述 投票:0回答:1
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int checkpalindrome(char* a,int n);
int main()
{
    char *a;
    int i,n;
    printf("Enter the size of the string but should be odd => ");
    scanf("%d",&n);
    a=(char*)calloc(n,sizeof(char));
    for(i=0;i<n;i++)
    {
        if(i==(n-1)/2)
        {  printf("Enter X\n");}
        scanf("%c",&a[i]);
    }
    if(checkpalindrome(a,n)){
      printf("\nstring is palindrome");
    }
    else{ 
      printf("\nstring is not a palindrome");
    }
    return 0;
}
int checkpalindrome(char *a,int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        if(a[i]==a[n-i])
          continue;
        else
          return 0;
    }
    return 1;
}

检查此代码,我没有得到正确的输出这里的字符串应该是a的和b的,而X应该在字符串的中间,我们必须检查该字符串是否是回文。

#include #include #include int checkpalindrome(char * a,int n); int main(){char * a; int i,n; printf(“输入字符串的大小,但是应该...

c string function stack
1个回答
0
投票

如果要在单个数组中实现两个堆栈,则需要将初始化数组的大小除以2。然后,必须通过这些基本初始化来区分两个堆栈。

© www.soinside.com 2019 - 2024. All rights reserved.