Novice C language learning journey(7)

in #art5 years ago

梦幻光晕蓝色背景矢量图.png
This is a function of string comparison.But it seems can not implement this function.
Pass the string "abc" to the two Formal parameters of "char s1" and "char s2".The Formal parameters1 is same as Formal parameters2.But the result is "s1!=s2".Because the value of "s1" and "s2" is already out of bounds when after executed "for" statement .So "s1!=s2".So the function is not return 0.
The code as follows:

int function(char *s1,char *s2){

  for(;*s1,*s2,*s1==*s2;s1++,s2++)   
         NULL;
   return *s1==*s2 ? 0 : *s1>*s2 ? 1 : -1;

}
The modified as follows:
int function(char* s1,char* s2){

   for(;*s1&&*s2&&*s1==*s2;s1++,s2++)
       NULL;
   return *s1==*s2?0:*s1>*s2?1:-1;

}

Sort:  

Congratulations @sky-999! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You published more than 10 posts. Your next target is to reach 20 posts.

You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

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!