ページ 1 / 1
文字列を比較したいのですが
Posted: 2012年1月20日(金) 20:07
by sa
文字列を比較したいのですが
strcmpってどうやって作られてるか
教えてください
Re: 文字列を比較したいのですが
Posted: 2012年1月20日(金) 20:35
by 史上最悪のデスペナ
Re: 文字列を比較したいのですが
Posted: 2012年1月20日(金) 20:58
by beatle
ちなみにglibcの実装はこちら
http://sourceware.org/git/?p=glibc.git; ... 4eef43e973
glibcのライセンスはLGPLですので,改造して配布するときはご注意下さい.
Re: 文字列を比較したいのですが
Posted: 2012年1月20日(金) 21:11
by たかぎ
こんな感じです。
コード:
int strcmp(const char *s1, const char *s2)
{
while (*s1 != '\0' && *s1 == *s2)
{
++s1;
++s2;
}
return (int)((unsigned char)*s1 - (unsigned char)*s2);
}