比较字符串

编程实现两个字符串s1和s2的字典序比较。(保证每一个字符串不是另一个的前缀,且长度在100以内)。若s1和s2相等,输出0;若它们不相等,则指出其第一个不同字符的ASCII码的差值:如果s1> s2,则差值为正;如果s1< s2,则差值为负。 
样例输入 
java  basic 
样例输出 

#include 
#include 
void main (void);
void main(void) {
	char s1[100];
	char s2[100];
	int i;

	scanf("%s",s1);
	scanf("%s",s2);
	if (strcmp(s1, s2) == 0)
		printf("0\n");
	else {

		for(i=0;; i++) 
		{
			if(s1[0]-s2[0]!=0) {
				printf("%d",s1[i]-s2[i]);
				break;
			}

		}

	}
}




你可能感兴趣的:(C/C++)