-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrcmp.c
48 lines (42 loc) · 1.01 KB
/
strcmp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*********************************************************************************
* Copyright: (C) 2017 qicheng
* All rights reserved.
*
* Filename: strcmp.c
* Description: This file
*
* Version: 1.0.0(07/29/2017)
* Author: yangni <[email protected]>
* ChangeLog: 1, Release initial version on "07/29/2017 06:01:09 AM"
*
********************************************************************************/
#include <stdio.h>
#include <string.h>
int mystrcmp(const char *s1, const char *s2)
{
int len1=strlen(s1);
int len2=strlen(s2);
int i;
for(i=0; i<=len1 && i<=len2; i++)
{
if(s1[i] > s2[i])
{
return 1;
}
if(s1[i] < s2[i])
{
return -1;
}
else if (s1[i] == s2[i])
{
return 0;
}
}
}
void main()
{
char a[20]="baaa";
char b[20]="aaaa";
int x=mystrcmp(a,b);
printf("%d",x);
}