You're welcome Pratik! :-) If you liked this video then you might you like some of the other videos in this playlist: th-cam.com/video/sepK5w4Uep0/w-d-xo.html
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: th-cam.com/video/aTSJFoqTZrI/w-d-xo.html.
@@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?
@@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. 🙂
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
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; }
Check out this video too on using recursion to check if a string is a palindrome! 🙂 th-cam.com/video/zQbX6r8MagM/w-d-xo.html.
this was the way i actually wanted to do it thanks mate upload more of this you are a clever man
You're welcome Pratik! :-) If you liked this video then you might you like some of the other videos in this playlist: th-cam.com/video/sepK5w4Uep0/w-d-xo.html
Perfectly explained! Thank you sir!
You're welcome Nicholas, I'm glad that you enjoyed the explanation! :-)
Thank you for this playlist
You're welcome Barnik! :-D
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.
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: th-cam.com/video/aTSJFoqTZrI/w-d-xo.html.
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
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
@@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?
@@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. 🙂
nice
Thanks!
it did not work for me
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
👍🏼👍🏼
Thanks Phanindra! :-)
Your code is really elegant and straightforward it makes so much easier to understand. Also, great pedagogical skills there. Thanks a lot!
Thank you so much for the positive feedback Victor, and you're very welcome! 😀
How come the if statement within the int main doesn't have {} am I cooked?
what would be the right code if i want the user to input any word to check
Malayalam is a great palindrome word
That’s a pretty long one, I’ll remember that thanks! :-)
@@PortfolioCourses haha sure. YOu should look it up. It's a south Indian Language that I speak.
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;
}
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;
}
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?
The length returned by strlen() does not count the null terminator, so that’s why it works out correctly length-wise.
@@PortfolioCourses Thank you!
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
It looks good to me Yunus, thanks for sharing! :-)
@@PortfolioCourses Thanks 😃
@@yunusemrebayraktar5147 🙂
nice
Thanks!
/0
I'm surprised you didn't calculate len and then calculated middle using len and save a function call.
Thank you so much
You’re very welcome! :-)
I got stuck on this in my 42 piscine final exam !