사용자 도구

사이트 도구


c_mystrcomp
/* mystrcomp.c: comparing the strings */
#include <stdio.h>
 
int mystrcomp(char *s1, char *s2);
 
int main(void) {
    char s[] = "Hello guys!";
    char ss[] = "It's a good day, isn't it?";
    int result;
 
    result = mystrcomp(s, ss);
 
    if(result == 0)
        printf("those are the same\n");
    else
        printf("those are different\n");
 
    return(0);
}
 
int mystrcomp(char *s1, char *s2) {
    char *p1 = &s1[0], *p2 = &s2[0];
 
    while(1)
    {   
        if(*p1 != *p2) 
            return *p1 - *p2; 
        if(*p1 == '\0' || *p2 == '\0')
            return 0;
        p1++;
        p2++;
    }
}
c_mystrcomp.txt · 마지막으로 수정됨: 2015/02/07 19:01 저자 jonghyouk