//wlasnorecznie ulepione string.h//dostepny na WTFPL (http://sam.zoy.org/wtfpl/).//autor: Krzysztof 'lordmorgul' Hankiewicz (http://lordmorgul.dyndns.org)//wykonane w vim 7.2.257, kompilowane i sprawdzane na GNU/Linux 2.6.31, openSUSE 11.2, gcc-4.4#include <stdio.h>#include <string.h>//#include <stdlib.h>char mystrcpy(char *s, char *t){ while (*s++ = *t++);}void mystrcat(char *s, const char *t){ while (*s++); s--; while (*s++ = *t++); }char *mystrchr(char *s, char t){ while ((*s)) { if (*s == t) return s; ++s; }}char *mystrstr(char *s, const char *t){ int i, j, k; for (i = 0; s[i]; i++) { for (j = i, k = 0; t[k] && s[j]; k++, j++) { if (t[k] != s[j]) break; else return &s[i]; } } }int mystrcmp(char *s, char *t){ int n; while(*s && *t && !(n = *s++ - *t++)); return n;}int mystrlen(char *c){ int n; for (n = 0; c[n]; n++); return n;}int main (void){ char *a = "kalafior"; char *b = "fior"; char c[12] = "loremipsum"; char d[12] = "kala"; printf("strcat:\t\t\"%s\" + ",d); mystrcat(d, b); printf("\"%s\" = \"%s\"\n\n", b,d); printf("strcpy:\t\tc[] wyglada obecnie tak: \"%s\"\n", c); mystrcpy (c, a); printf("\t\tPo skopiowaniu do c[] \"%s\" dostajemy c[]=\"%s\"\n\n", a, c); printf("strstr:\t\t\"%s\" pojawia sie w \"%s\" w miejscu %s\n\n", b, a, mystrstr(a, b)); printf("strchr:\t\t\"%s\" po raz pierwszy pojawia sie w %s\n\n", a, mystrchr(a, 'l')); printf("strcmp:\t\t%d\n", mystrcmp(a, d)); if (mystrcmp(a,d) == 0) printf("\t\tstringi \"%s\" i \"%s\" sa identyczne\n\n", a, d); else printf("\t\t\"%s\" wystepuje przed \"%s\"\n\n", (mystrcmp(a, d) > 0) ? a : d, (mystrcmp(a, d) < 0) ? a : d); printf("\t\t%d\n\n", mystrcmp(b, a)); if (mystrcmp(b,a) == 0) printf("\t\tstringi \"%s\" i \"%s\" sa identyczne\n\n", b, a); else printf("\t\t\"%s\" wystepuje przed \"%s\"\n\n", (mystrcmp(b, a) < 0) ? b : a, (mystrcmp(b, a) > 0) ? b : a); printf("strlen:\t\tDlugosc stringa \"%s\" to %d\n", a,mystrlen(a)); return 0;}