#include <stdio.h> #include <string.h> int main(void) { char str[] = "ABC"; printf("ABC: ABD = %d\n", strncmp(str, "ABD", 2)); printf("ABC: ABC = %d\n", strncmp(str, "ABC", 2)); printf("ABC: AAA = %d\n", strncmp(str, "AAA", 2)); printf("ABC: ABCD = %d\n", strncmp(str, "ABCD", 2)); printf("ABC: AB = %d\n", strncmp(str, "AB", 2)); printf("ABC: B = %d\n", strncmp(str, "B", 2)); printf("ABC: A = %d\n", strncmp(str, "A", 2)); return 0; }
【実行結果例】※処理系により値は異なる
ABC: ABD = 0 ABC: ABC = 0 ABC: AAA = 1 ABC: ABCD = 0 ABC: AB = 0 ABC: B = -1 ABC: A = 1 |
▼戻る▼
「初心者のためのポイント学習C言語」 Copyright(c) 2000-2004 TOMOJI All Rights Reserved