I watched 5+ videos about strcmp but only this one explain well because some other tutorials i watched they're like explaining to learner that already knowledge in strcmp. Thankyou!
Haha... I don't mind dark mode for coding, especially at night. But it doesn't make a big difference to me either way. Personally I've found dark mode tutorials a bit harder to read along with on UA-cam because the video size is typically smaller. And so the higher contrast of a typical 'light mode' makes things easier to read in a smaller UA-cam window, at least for me anyways.
You're welcome! And thank you for the kind words. Learning to program can be very challenging and it's easy to get discouraged, but if you practice enough for a long enough time it starts to get easier. Searching for answers and different ways of understanding something is something *smart* people do - you got this! :-)
It looks like strcmp does a subtraction. When the subtraction (s1-s2) is non-zero, then the returned number is the difference at that point between the two ASCII values. So "abc" an "abd" would give -1. "abc" and "abm" gives -10, the difference in the ASCII representations of 'c' (99) and 'm' (109) Might turn out useful....
Nice video. Thanks :) Whats funny to me is that if you wanted to just compare 1 specific character in a string something like this would work: char message [ ] = "Hello"; char greeting [ ] = "Hey"; if (message[0] == greeting[0]){ printf("Character 0: Huzzah! Equality "); } else { printf("Character 0: Nah, not equal "); } If you wanted to compare a specific place in the strings you might use something like this, rather than strcmp. Pretty neat.
You're welcome, I'm glad you enjoyed it! :-) I love low-level programming like C, but sometimes it's nice to use something like Python where we can check if strings are equal with a simple == operator.
Great question! 🙂If you have something like: char mystring[] = "my string"; char *s = mystring; Where 's' is assigned to point to a string, than it will point to the first char of the string. And *s will give us the first char of the string ('m'), *(s + 1) will give us the next char in the string ('y), and so on.
I watched 5+ videos about strcmp but only this one explain well because some other tutorials i watched they're like explaining to learner that already knowledge in strcmp. Thankyou!
You're welcome John, I'm so glad to hear you found this video helpful! :-)
So well spoken. Brilliant video. Thank you so much!
You're welcome Matthew! :-) And thank you for the kind words.
this is the only guy who doesn't codes in dark mode😂
Haha... I don't mind dark mode for coding, especially at night. But it doesn't make a big difference to me either way. Personally I've found dark mode tutorials a bit harder to read along with on UA-cam because the video size is typically smaller. And so the higher contrast of a typical 'light mode' makes things easier to read in a smaller UA-cam window, at least for me anyways.
I am israeli man and i dont know english fluently. however, i succed to understand your tuorial!!
tank you!
You're welcome, I'm glad the tutorial was still able to help you out! :-)
awesome content😃😃
my school prof tried his best to teach me this topic but dumb me couldn't understand anything..
thank you so much😎😎
You're welcome! And thank you for the kind words. Learning to program can be very challenging and it's easy to get discouraged, but if you practice enough for a long enough time it starts to get easier. Searching for answers and different ways of understanding something is something *smart* people do - you got this! :-)
It looks like strcmp does a subtraction. When the subtraction (s1-s2) is non-zero, then the returned number is the difference at that point between the two ASCII values. So "abc" an "abd" would give -1. "abc" and "abm" gives -10, the difference in the ASCII representations of 'c' (99) and 'm' (109) Might turn out useful....
Nice video. Thanks :)
Whats funny to me is that if you wanted to just compare 1 specific character in a string something like this would work:
char message [ ] = "Hello";
char greeting [ ] = "Hey";
if (message[0] == greeting[0]){
printf("Character 0: Huzzah! Equality
");
}
else {
printf("Character 0: Nah, not equal
");
}
If you wanted to compare a specific place in the strings you might use something like this, rather than strcmp. Pretty neat.
You're welcome, I'm glad you enjoyed it! :-) I love low-level programming like C, but sometimes it's nice to use something like Python where we can check if strings are equal with a simple == operator.
Nice job buddy!
I'm glad you enjoyed it! :-)
What's the preprocessor directives for strcmp? It says i should have a prototype
You need to include string.h to use the function. :-)
What happens if you try to dereference the strings to point refer to the string values instead of the addresses?
Great question! 🙂If you have something like:
char mystring[] = "my string";
char *s = mystring;
Where 's' is assigned to point to a string, than it will point to the first char of the string. And *s will give us the first char of the string ('m'), *(s + 1) will give us the next char in the string ('y), and so on.
built this, i want some feedback:
int str_cmp(const char* str1, const char* str2) {
size_t str1_length = strlen(str1);
size_t str2_length = strlen(str2);
if (str1_length == str2_length) {
for (size_t i = 0; i < str1_length; i++) {
if (str1[i] != str2[i]) {
if (str1[i] > str2[i]) {
return 1;
} else {
return -1;
}
}
}
} else {
int min_len = (str1_length > str2_length ? str2_length : str1_length);
for (size_t i = 0; i < min_len; i++) {
if (str1[i] > str2[i]) {
return 1;
} else {
return -1;
}
}
return (min_len == str1_length ? -1 : 1);
}
return 0;
}
Of course he has a video on it :) Will definitely donate through the "Thanks button". (Soon). I will send like 30 usd.
Awesome, thank you! :-)