Novice C language learning journey(7)

in Project HOPE5 years ago (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;

}

Sort:  
 5 years ago  

Hi @sky-999

I think your content would fit programming hive (managed by @cadawg): https://steemit.com/trending/hive-169321

Yours, Piotr

Thanks for the mention @crypto.piotr.

@sky-999 I'd love to have you post there!

 5 years ago  

Glad I could help :)

Welcome to steemit @sky-999.

Welcome the new steemians. Have a great day!

 5 years ago  Reveal Comment