Question #6495   Submitted by Answiki on 08/25/2022 at 07:57:45 PM UTC

How to write a C function that check if a string is the same when read backward?

Answer   Submitted by Answiki on 08/25/2022 at 07:56:19 PM UTC

The following C function returns 1 if the string is a palindrome , 0 otherwise:

char isPalindromic(char s[]) {
  int i, length;
  length = strlen(s);
  for (i=0; i<length/2; i++) 
    if (s[i] != s[length-1-i]) return 0;  
  return 1;
}

This function is space and case sensitive: the words "RAdar" or "ra dar" will not be considered as palindromes.


5 events in history
Question by Answiki 08/25/2022 at 07:58:10 PM
How to write a C function that check if a string reads the same forwards as backwards?
Question by Answiki 08/25/2022 at 07:57:45 PM
How to write a C function that check if a string is the same when read backward?
Question by Answiki 08/25/2022 at 07:57:32 PM
How to write a C function that check if a word is the same when read backward?
Answer by Answiki on 08/25/2022 at 07:56:19 PM

The following C function returns 1 if the string is a palindrome , 0 otherwise:

char isPalindromic(char s[]) {
  int i, length;
  length = strlen(s);
  for (i=0; i<length/2; i++) 
    if (s[i] != s[length-1-i]) return 0;  
  return 1;
}

This function is space and case sensitive: the words "RAdar" or "ra dar" will not be considered as palindromes.


Question by Answiki 08/25/2022 at 07:47:04 PM
How to write in C a function that tests if a word is a palindrome?
# ID Query URL Count

Icons proudly provided by Friconix.