Novice C language learning journey(8)

in Programming5 years ago (edited)

梦幻光晕蓝色背景矢量图.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;
  }
Sort:  

Thank you for posting in the programming community.

Best of luck on your journey. Upvoted.

thank you.

Coin Marketplace

STEEM 0.21
TRX 0.20
JST 0.034
BTC 98129.50
ETH 3322.67
USDT 1.00
SBD 3.05