C语言Matrix编程题——[Pointers and C-String]D. Liang 7.7 Checking palindrome

[Pointers and C-String]D. Liang 7.7 Checking palindrome

Description:

A string is a palindrome if it reads the same forward and backward. The word “mom,” “dad,” and “moon,” for example, are all palindromes.
Write a function to check whether a string is a palindrome, ignore case. For example, “Mom” is a palindrome when we ignore case.
The function header is:

int isPalindrome(const char * const s)

Hint:

Don’t submit the main() function.

Programme:

//Date:2020/5/13
//Author:Kamenrider Justice
int isPalindrome(const char * const s)
{
   int length,i,j=0,flag=1;
   length=strlen(s);//获取字符串长度
   char array[length+1];//+1是因为如果全部都是字母的话,最后一位在后面会被赋值'\0'
   for(i=0;i<length;i++)
   {
      if(isalpha(s[i]))
      {
         array[j]=tolower(s[i]);//全部变小写储存到数组
         j++;
      }
   }
   array[j]='\0';//不一定全部占满了数组,所以人为地截止
   length=strlen(array);//获取新的数组长度
   for(i=0;i<length/2;i++)
   {
      if(array[i]!=array[length-i-1])
      {
         flag=0;
      }
   }
   return flag;
}

PyTorch从入门到实战一次学会

你可能感兴趣的:(C语言Matrix)