Novice C language learning journey(7)

avatar
(Edited)

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

}



0
0
0.000
5 comments
avatar

According to the Bible, Bro. Eli: How many heavens are there according to the Bible?

Watch the Video below to know the Answer...

(Sorry for sending this comment. We are not looking for our self profit, our intentions is to preach the words of God in any means possible.)


Comment what you understand of our Youtube Video to receive our full votes. We have 30,000 #SteemPower. It's our little way to Thank you, our beloved friend.
Check our Discord Chat
Join our Official Community: https://steemit.com/created/hive-182074

0
0
0.000