#include <stdio.h>
#include <string.h>
int main(void)
{
char buf1[] = "\0abc\0de"; /* 途中に空文字のある文字列 */
char buf2[] = "\0abc\0de";
char buf3[] = "\0abcdef";
if (memcmp(buf1, buf2, 7) == 0)
printf("buf1 = buf2\n");
else
printf("buf1 != buf2\n");
if (memcmp(buf1, buf3, 7) == 0)
printf("buf1 = buf3\n");
else
printf("buf1 != buf3\n");
return 0;
}
【実行結果】buf1 = buf2 buf1 != buf3 ※ 途中に空文字があっても比較できる。
▼戻る▼
「初心者のためのポイント学習C言語」 Copyright(c) 2000-2004 TOMOJI All Rights Reserved