Strcmp Implementation in C

Strcmp compares the string “s1” to the string “s2” and gives the results of the comparison.
“i” is zero if the strings are identical.
“i” is positive if string “s1” is greater than string “s2”
“i” is negative negative if string “s2” is greater than string “s1”.
Both strings must be terminated by the usual ‘\0’ character.
StrCmp implementation in C Program
#include< stdio.h >
int strcomp(char *, char *);
int main(){
char *ch1=”Welcome”;
char *ch2=”Welcome”;
int i;
i=strcomp(ch1,ch2);
if(i==0){
printf(“Both are Same”);
}
else{
printf(“Both are Different”);
}
return 0;
}
int strcomp(char *ch1, char *ch2)
{
while(*ch1==*ch2) {
    if(*s1==’\0′)
        return (0);
    ch1++;
    ch2++;
}
return (*ch1 -*ch2);
}

About mohan

This is Mohan Jayapalan author of TechPages Blog.I am a part time blogger and Currently working for private Software Concern.

© Copyright 2010-2016 www.techpages.org · All Rights Reserved · Powered by WordPress ·