strcmp() function | C Programming Tutorial

Поділитися
Вставка
  • Опубліковано 22 гру 2024

КОМЕНТАРІ • 22

  • @virgo2004
    @virgo2004 Рік тому +2

    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!

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

      You're welcome John, I'm so glad to hear you found this video helpful! :-)

  • @matthewbnguyen
    @matthewbnguyen 2 роки тому +5

    So well spoken. Brilliant video. Thank you so much!

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

      You're welcome Matthew! :-) And thank you for the kind words.

  • @lyrichives7859
    @lyrichives7859 2 роки тому +18

    this is the only guy who doesn't codes in dark mode😂

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

      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.

  • @nadavAminov
    @nadavAminov Рік тому +2

    I am israeli man and i dont know english fluently. however, i succed to understand your tuorial!!
    tank you!

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

      You're welcome, I'm glad the tutorial was still able to help you out! :-)

  • @misterrandompro6181
    @misterrandompro6181 2 роки тому +6

    awesome content😃😃
    my school prof tried his best to teach me this topic but dumb me couldn't understand anything..
    thank you so much😎😎

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

      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! :-)

  • @baruchben-david4196
    @baruchben-david4196 Рік тому +1

    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....

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

    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.

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

      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.

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

    Nice job buddy!

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

    What's the preprocessor directives for strcmp? It says i should have a prototype

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

    What happens if you try to dereference the strings to point refer to the string values instead of the addresses?

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

      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.

  • @deepblackoutlaw9640
    @deepblackoutlaw9640 10 місяців тому

    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;
    }

  • @X-VIPRIN
    @X-VIPRIN Рік тому +1

    Of course he has a video on it :) Will definitely donate through the "Thanks button". (Soon). I will send like 30 usd.