Check If A String Is A Palindrome | C Programming Example

Поділитися
Вставка
  • Опубліковано 24 сер 2024
  • An example of how to check whether a string is a palindrome using C. Source code: github.com/por.... Check out www.portfolioc... to build a portfolio that will impress employers!

КОМЕНТАРІ • 41

  • @PortfolioCourses
    @PortfolioCourses  Рік тому +1

    Check out this video too on using recursion to check if a string is a palindrome! 🙂 ua-cam.com/video/zQbX6r8MagM/v-deo.html.

  • @victor.san3
    @victor.san3 2 роки тому +11

    Your code is really elegant and straightforward it makes so much easier to understand. Also, great pedagogical skills there. Thanks a lot!

    • @PortfolioCourses
      @PortfolioCourses  2 роки тому

      Thank you so much for the positive feedback Victor, and you're very welcome! 😀

  • @pratikthapa6218
    @pratikthapa6218 2 роки тому +1

    this was the way i actually wanted to do it thanks mate upload more of this you are a clever man

    • @PortfolioCourses
      @PortfolioCourses  2 роки тому

      You're welcome Pratik! :-) If you liked this video then you might you like some of the other videos in this playlist: ua-cam.com/video/sepK5w4Uep0/v-deo.html

  • @nicholas_sergakis
    @nicholas_sergakis Рік тому +1

    Perfectly explained! Thank you sir!

    • @PortfolioCourses
      @PortfolioCourses  Рік тому

      You're welcome Nicholas, I'm glad that you enjoyed the explanation! :-)

  • @barnikroy5244
    @barnikroy5244 2 роки тому +2

    Thank you for this playlist

  • @justcurious1940
    @justcurious1940 8 місяців тому +1

    Just a string a weird syndrome :
    _Bool is_Syndrome(char *string){
    int length = strlen(string);
    int middle = length/2;
    for(int i = 0 ; i < middle ; i++){
    if(string[i] != string[length-1-i])
    return false;
    }
    return true;
    }

    • @comoyun
      @comoyun 2 місяці тому

      looks similar to mine:
      int isPalindrome(char word[]) {
      int status = 1, i = -1,
      length = 0;
      while (word[++length] != '\0');
      while (i++ < length / 2) {
      if (word[i] != word[length - i - 1]) {
      status = 0;
      break;
      }
      }
      return status;
      }

  • @omarmohamed-zo3dp
    @omarmohamed-zo3dp Місяць тому

    what would be the right code if i want the user to input any word to check

  • @pogCibi
    @pogCibi 7 місяців тому +1

    I have a question, doesn't the strings also have a terminating null character 0? So why is it not a problem when we are taking it's lenght?

    • @PortfolioCourses
      @PortfolioCourses  7 місяців тому +3

      The length returned by strlen() does not count the null terminator, so that’s why it works out correctly length-wise.

    • @pogCibi
      @pogCibi 7 місяців тому +1

      @@PortfolioCourses Thank you!

  • @charlescox290
    @charlescox290 6 місяців тому

    I'm surprised you didn't calculate len and then calculated middle using len and save a function call.

  • @EuaggelosSP
    @EuaggelosSP Рік тому +1

    What do I do if I want my program to ignore cases, for example if I input Wow it says its not a palindrome because of the capital W.

    • @PortfolioCourses
      @PortfolioCourses  Рік тому +1

      Great question! :-) One thing you could do is include the ctype libray at the top of the file with #include and then change this line to:
      if (tolower(string[i]) != tolower(string[len - i - 1])) return false;
      The tolower() function will convert both letters to lowercase letters (if they are uppercase letters, otherwise it just returns the original character). The function is covered in this video if you want to learn more: ua-cam.com/video/aTSJFoqTZrI/v-deo.html.

  • @tanker1425
    @tanker1425 7 місяців тому +1

    nice

  • @user-it9cy4qu3f
    @user-it9cy4qu3f 10 місяців тому

    Thank you so much

  • @yunusemrebayraktar5147
    @yunusemrebayraktar5147 Рік тому +1

    int main() {

    int i, length, check;
    char string[20];
    char reverse_string[20];

    printf("Enter a string: ");
    scanf("%s", string);
    length = strlen(string);
    for(i=0;i

  • @umarahmed3113
    @umarahmed3113 2 роки тому

    So I got the right code for the palindrome if it’s something like aabaa but I don’t know what to do for something like aabaaa

    • @PortfolioCourses
      @PortfolioCourses  2 роки тому

      Did you try the code in this video? 🙂 It is available here and it should work: github.com/portfoliocourses/c-example-code/blob/main/palindrome.c

    • @umarahmed3113
      @umarahmed3113 2 роки тому

      @@PortfolioCourses im not sure if ittl work because im doing the leetcode on a site called codesignal. If you're able to do the coding for that task on there, can you make a tutorial?

    • @PortfolioCourses
      @PortfolioCourses  2 роки тому

      @@umarahmed3113 If it's C they're using, it should work on there too. 🙂 I'm not sure if I can do a tutorial on that, maybe one day I can cover some leetcode questions as it does seem to be popular with learners. 🙂

  • @DLikeDick
    @DLikeDick 6 місяців тому

    I got stuck on this in my 42 piscine final exam !

  • @SketchupGuru
    @SketchupGuru Рік тому +1

    Malayalam is a great palindrome word

    • @PortfolioCourses
      @PortfolioCourses  Рік тому +1

      That’s a pretty long one, I’ll remember that thanks! :-)

    • @SketchupGuru
      @SketchupGuru Рік тому

      @@PortfolioCourses haha sure. YOu should look it up. It's a south Indian Language that I speak.

  • @glennpableo7030
    @glennpableo7030 2 роки тому

    it did not work for me

    • @PortfolioCourses
      @PortfolioCourses  2 роки тому +1

      Can you post your code in a comment here so we can check it out? The original code is found here, it should work: github.com/portfoliocourses/c-example-code/blob/main/palindrome.c

  • @phanindraslvs7469
    @phanindraslvs7469 Рік тому

    👍🏼👍🏼

  • @ArjunA-ln3ov
    @ArjunA-ln3ov 3 місяці тому

    /0

  • @tanker1425
    @tanker1425 7 місяців тому

    nice