EmbLogic's Blog

function of strcmp

1 #include<stdio.h>
2 #include<stdlib.h>
3
4 int stcmp(char *str1 ,char *str2)
5 {
6         int dif,i=0;
7         while(str1[i]!=”||str2[i]!=”)
8         {
9                  dif=(str1[i]-str2[i]);
10                 if(dif!=0)
11                 {
12                   break;
13                 }
14                 i++;
15         }
16         if(dif>0)
17         {
18                  printf(“-%d”,dif);
19         }
20         else
21         {
22                 if(dif<0)
23                 {
24                 printf(“%d”,dif);
25                 }
26                 else
27                 {
28                         printf(“0″);
29                 }
30         }
31         }
32
33 main()
34 {
35
36
37         stcmp(“bcd”,”abc”);
38 }

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>