Programming/기초

문자열 비교

KingSSSSS 2018. 5. 26. 21:08
int my_strcmp(const char * pStr1, const char * pStr2) {
	if (pStr1 == NULL || pStr2 == NULL) return -1;
 
	for (; (*pStr1) != '\0' || (*pStr2) != '\0'; pStr1++, pStr2++) {
		if ((*pStr1) > (*pStr2))        return 1;
		if ((*pStr1) < (*pStr2))        return -1;
	}
 
	return 0;
}