编写函数scomp(char *s1,char *s2),将两个字符串s1和s2进行比较,要求若s1= s2,函数返回值为0;若s1≠s2,返回它们二者第一个不同字符的ASCII码差值(如:“BOY”与“BAD”,第2个字母不同,“O”与“A” 之差为79-65=14), 即s1> s2,函数返回值为正数;若s1< s2,函数返回值为负数。在主函数调用scomp函数并输出返回值。
#include < stdio. h >
#include < string. h >
int main ( )
{
int scomp ( char *s1, char *s2 ) ; //声明函数
char str1 [ 10 ], srt2 [ 10 ] ;// 定义字符