Novice C language learning journey(7)

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@sky-999·
0.000 HBD
Novice C language learning journey(7)
![梦幻光晕蓝色背景矢量图.png](https://cdn.steemitimages.com/DQmeWGa19sY4X6wLEcCrmGeR1RAM1emGEyft1vytQcnqxVo/%E6%A2%A6%E5%B9%BB%E5%85%89%E6%99%95%E8%93%9D%E8%89%B2%E8%83%8C%E6%99%AF%E7%9F%A2%E9%87%8F%E5%9B%BE.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;
}
👍 , , , , , , , , , , , , , , , , , ,