scrobble.life
Project HOPE

Novice C language learning journey(8)

梦幻光晕蓝色背景矢量图.png How to judge the two string that is it equal?I try run the code as follows.But it can not implement the function.Because it directly take the two string to compare.The code as follows:

     #include"stdio.h"
     #include"stdlib.h"
     main(){
     char m[5];
     if(gets(m)=="abc")
           printf("a\n");
     else
           printf("b\n");
     system("pause");
     }

So how to modify? I create a function be used to compare.Put the every character to compare.The code as follows:

      #include <stdio.h>
      int _strcmp(char *s1, char *s2)
      {
      for (; *s1 && *s2 && *s1==*s2; ++s1,++s2) NULL;
      return *s1==*s2 ? 0 : *s1>*s2 ? 1 : -1;
      }
      int main(void){
      char m[5];
      if (_strcmp(gets(m),"abc") == 0)
            printf("a\n");
      else
            printf("b\n");
      return 0;
      }

Comments · 7

  • @arcange(79)· 2371d

    Congratulations @sky-999! Your post was mentioned in the Steem Hit Parade for newcomers in the following category:

    • Comments - Ranked 10 with 6 comments
  • @juanmolina(70)· 2372d

    Wow! These things are too advanced for me.

    Thanks for posting on Project Hope.

  • @tuanis(59)· 2372d

    Welcome to steemit @sky-999.

    • Join @minnowsupport project for more help
    • Checkout @helpie for daily trivias and useful information
    • Join @qurator a good quality support project
    • Checkout @steembasicincome
    • Help us save the forest with @treeplanter

    Welcome the new steemians. Have a great day!

  • @ddn688(67)· 2372d

    Wrong tag for right post. People will welcome you for this post

  • @coffeebreak(53)· 2372d

    Hey sky-999! If you would like to make your personal feed contain the top trending media and talking points of the whole internet, consider following @coffeebreak and @topicstoday accounts - And welcome to Steem!

  • @coffeebreak(53)· 2373d

    Hey sky-999! If you would like to make your personal feed contain the top trending media and talking points of the whole internet, consider following @coffeebreak and @topicstoday accounts - And welcome to Steem!

  • @silent-ghost(9)· 2373d

    Welcome to Steemit @sky-999 :)