#include #include #include #include "string.h" static char smp[][256] = { "a", "A", "あ", "ア", "ア", "・", "。", "!", "!", "abc", "ABC", "aAA", "abcABC12345ABCabcあいうアイウあわあabcテーブル表テーブル表", "ABCabcあいう     アイウ\\ aあわあテーブル表テーブル表   ", "                       ", "zabc aaa de a g \t asdfasdfkl  \\\n\n\nooo !", "", "", "", "", }; int main(void) { char *p, buf[1024*16],*s; int i,n=0,c; printf("\n[%d]strcpy\n", ++n); memset(buf, 0,sizeof(buf)); for (i = 0; smp[i][0]; i++) { strcpy(buf, smp[i]); printf("%d %d> (%d) %s\n", n, i, strlen(buf), buf); } printf("\n[%d]strncpy\n", ++n); memset(buf, 0,sizeof(buf)); for (i = 0; smp[i][0]; i++) { strncpy(buf, smp[i], 20); printf("%d %d> (%d) %s\n", n, i, strlen(buf), buf); } printf("\n[%d]memccpy\n", ++n); memset(buf, 0,sizeof(buf)); for (i = 0; smp[i][0]; i++) { p = memccpy(buf, smp[i], 'c', 20); if (p) printf("%d %d> %s\n", n, i, p); else printf("(null)\n"); } printf("\n[%d]memmove\n", ++n); memset(buf, 0,sizeof(buf)); for (i = 0; smp[i][0]; i++) { p = memmove(buf, smp[i], 256); printf("%d %d> %s\n", n, i, p); p = memmove(buf+1, buf+5, 3); printf("%d %d> %s\n", n, i, p); p = memmove(buf+6, buf+3, 47); printf("%d %d> %s\n", n, i, p); } printf("\n[%d]strrev\n", ++n); for (i = 0; smp[i][0]; i++) { strncpy(buf, smp[i], 256); p = strrev(buf); printf("%d %d> %s\n", n, i, p); } printf("\n[%d]strncat 256\n", ++n); memset(buf,0,sizeof(buf)); for (i = 0; smp[i][0]; i++) { p = strncat(buf, smp[i], 256); printf("%d %d> %s\n", n, i, p); } printf("\n[%d]strncat 20\n", ++n); memset(buf,0,sizeof(buf)); for (i = 0; smp[i][0]; i++) { memset(buf,0,sizeof(buf)); p = strncat(buf, smp[i], 20); printf("%d %d> (%d) ", n, i, strlen(p)); printf("%s\n", p); } printf("\n[%d]strchr\n", ++n); for (i = 0; smp[i][0]; i++) { strcpy(buf, smp[i]); p = strchr(buf,'A'); if (p) printf("1 %d %d> %s\n", n, i, p); p = strchr(buf,'\\'); if (p) printf("2 %d %d> %s\n", n, i, p); p = strchr(buf,0x82a0); if (p) printf("3 %d %d> %s\n", n, i, p); } printf("\n[%d]strrchr\n", ++n); for (i = 0; smp[i][0]; i++) { strcpy(buf, smp[i]); p = strrchr(buf,'a'); if (p) printf("1 %d %d> %s\n", n, i, p); p = strrchr(buf,'\\'); if (p) printf("2 %d %d> %s\n", n, i, p); p = strrchr(buf,0x82a0); if (p) printf("3 %d %d> %s\n", n, i, p); } printf("\n[%d]strcmp\n", ++n); c = strcmp("", ""); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); for (i = 0; smp[i][0]; i++) { c = strcmp("", smp[i]); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = strcmp("a", smp[i]); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = strcmp("abc", smp[i]); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = strcmp("・", smp[i]); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = strcmp("A", smp[i]); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = strcmp("\x82", smp[i]); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = strcmp("   ", smp[i]); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); } printf("\n[%d]stricmp\n", ++n); for (i = 0; smp[i][0]; i++) { c = stricmp("", smp[i]); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = stricmp("a", smp[i]); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = stricmp("abc", smp[i]); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = stricmp("・", smp[i]); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = stricmp("A", smp[i]); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = stricmp("\x82", smp[i]); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = stricmp("   ", smp[i]); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); } printf("\n[%d]strncmp\n", ++n); c = strncmp("", "", 0); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = strncmp("", "", 1); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); for (i = 0; smp[i][0]; i++) { c = strncmp("", smp[i], 1); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = strncmp("a", smp[i], 1); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = strncmp("abc", smp[i], 3); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = strncmp("abc", smp[i], 4); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = strncmp("・", smp[i], 2); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = strncmp("A", smp[i], 2); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = strncmp("\x82", smp[i], 1); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = strncmp("   ", smp[i], 6); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); } printf("\n[%d]strnicmp\n", ++n); for (i = 0; smp[i][0]; i++) { c = strnicmp("", smp[i], 1); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = strnicmp("a", smp[i], 1); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = strnicmp("abc", smp[i], 3); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = strnicmp("・", smp[i], 2); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = strnicmp("A", smp[i], 2); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = strnicmp("\x82", smp[i], 1); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = strnicmp("   ", smp[i], 6); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); } printf("\n[%d]memcmp\n", ++n); c = memcmp("", "", 0); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = memcmp("", "", 1); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); for (i = 0; smp[i][0]; i++) { c = memcmp("", smp[i], 1); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = memcmp("a", smp[i], 1); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = memcmp("abc", smp[i], 3); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = memcmp("abc", smp[i], 4); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = memcmp("・", smp[i], 2); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = memcmp("A", smp[i], 2); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = memcmp("\x82", smp[i], 1); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = memcmp("   ", smp[i], 6); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); } printf("\n[%d]memicmp\n", ++n); c = memicmp("", "", 0); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = memicmp("", "", 1); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); for (i = 0; smp[i][0]; i++) { c = memicmp("", smp[i], 1); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = memicmp("a", smp[i], 1); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = memicmp("abc", smp[i], 3); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = memicmp("abc", smp[i], 4); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = memicmp("・", smp[i], 2); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = memicmp("A", smp[i], 2); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = memicmp("\x82", smp[i], 1); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); c = memicmp("   ", smp[i], 6); printf("%d\n", (c < 0) ? -1 : (c > 0) ? 1 : 0); } printf("\n[%d]strupr\n", ++n); for (i = 0; smp[i][0]; i++) { strncpy(buf, smp[i], 256); p = strupr(buf); printf("%s\n", p); } printf("\n[%d]strlwr\n", ++n); for (i = 0; smp[i][0]; i++) { strncpy(buf, smp[i], 256); p = strlwr(buf); printf("%s\n", p); } printf("\n[%d]strset\n", ++n); for (i = 0; smp[i][0]; i++) { strncpy(buf, smp[i], 256); p = strset(buf,0x8145); printf("%s\n", p); } printf("\n[%d]strnset\n", ++n); for (i = 0; smp[i][0]; i++) { memmove(buf, smp[i], 256); p = strnset(buf,0x8145, 7); printf("%s\n", p); } printf("\n[%d]memset\n", ++n); for (i = 0; smp[i][0]; i++) { memcpy(buf, smp[i], 256); p = memset(buf, '-', strlen(smp[i])); printf("%s\n", p); } printf("\n[%d]strspn\n", ++n); for (i = 0; smp[i][0]; i++) { p = strncpy(buf, smp[i], 256); c = strspn(buf, s=""); if (c) printf("%d %d> %d %s(%s,%s)\n", n, i, c,p,s,buf); c = strspn(buf, s="\\"); if (c) printf("%d %d> %d %s(%s,%s)\n", n, i, c,p,s,buf); c = strspn(buf, s="\\abc"); if (c) printf("%d %d> %d %s(%s,%s)\n", n, i, c,p,s,buf); c = strspn(buf, s="\\aAbc"); if (c) printf("%d %d> %d %s(%s,%s)\n", n, i, c,p,s,buf); c = strspn(buf, s="あbc"); if (c) printf("%d %d> %d %s(%s,%s)\n", n, i, c,p,s,buf); c = strspn(buf, s="abcABC"); if (c) printf("%d %d> %d %s(%s,%s)\n", n, i, c,p,s,buf); } printf("\n[%d]strcspn\n", ++n); for (i = 0; smp[i][0]; i++) { p=strncpy(buf, smp[i], 256); c = strcspn(buf, ""); if (c) printf("%d %d> %d %s\n", n, i, c,p); c = strcspn(buf, "\\"); if (c) printf("%d %d> %d %s\n", n, i, c,p); c = strcspn(buf, "\\abc"); if (c) printf("%d %d> %d %s\n", n, i, c,p); c = strcspn(buf, "\\aAbc"); if (c) printf("%d %d> %d %s\n", n, i, c,p); c = strcspn(buf, "あbc"); if (c) printf("%d %d> %d %s\n", n, i, c,p); c = strcspn(buf, "abcABC"); if (c) printf("%d %d> %d %s\n", n, i, c,p); } printf("\n[%d]strpbrk\n", ++n); for (i = 0; smp[i][0]; i++) { strncpy(buf, smp[i], 256); p = strpbrk(buf, ""); if (p) printf("%d %d> %s\n", n, i, p); p = strpbrk(buf, "\\"); if (p) printf("%d %d> %s\n", n, i, p); p = strpbrk(buf, "\\abc"); if (p) printf("%d %d> %s\n", n, i, p); p = strpbrk(buf, "\\aAbc"); if (p) printf("%d %d> %s\n", n, i, p); p = strpbrk(buf, "あbc"); if (p) printf("%d %d> %s\n", n, i, p); p = strpbrk(buf, "abcABC"); if (p) printf("%d %d> %s\n", n, i, p); } #if 10 printf("\n[%d]strtok\n", ++n); fflush(stdout); //printf("%x\n", n, i, strtok("abcd", NULL)); //fflush(stdout); for (i = 0; smp[i][0]; i++) { p = strncpy(buf, smp[i], 256); while ((p = strtok(p, "a")) != NULL) { printf("%d %d> %s\n", n, i, p); fflush(stdout); p = NULL; } p = strncpy(buf, smp[i], 256); while ((p = strtok(p, "AaA")) != NULL) { printf("%d %d> %s\n", n, i, p); fflush(stdout); p = NULL; } p = strncpy(buf, smp[i], 256); while ((p = strtok(p, "\\ 表")) != NULL) { printf("%d %d> %s\n", n, i, p); fflush(stdout); p = NULL; } } printf("\n[%d]strstr\n", ++n); for (i = 0; smp[i][0]; i++) { strncpy(buf, smp[i], 256); p = strstr(buf, ""); if (p) printf("%d %d> %s\n", n, i, p); p = strstr(buf, "\\"); if (p) printf("%d %d> %s\n", n, i, p); p = strstr(buf, "abc"); if (p) printf("%d %d> %s\n", n, i, p); p = strstr(buf, "表"); if (p) printf("%d %d> %s\n", n, i, p); p = strstr(buf, "Ca"); if (p) printf("%d %d> %s\n", n, i, p); p = strstr(buf, "表テーブル表"); if (p) printf("%d %d> %s\n", n, i, p); p = strstr(buf, "   "); if (p) printf("%d %d> %s\n", n, i, p); } #endif #if 0 printf("\n[%d]_swab\n", ++n); for (i = 0; smp[i][0]; i++) { _swab(smp[i], buf, 10); printf("%s\n", buf); } #endif return 0; }