All pastes #1768645 Raw Edit

mystrings.c

public c v1 · immutable
#1768645 ·published 2010-01-27 23:04 UTC
rendered paste body
#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++); }/*void *mystrchr(char *s, char t){	while (!(*s++))	{		if (*s == t) return s;	}}*/char* mystrchr(char* zrodlo, int c) // od krystiana. tez jebie bledami.{	char* wsk = zrodlo;	while(*wsk++)	if( c == *wsk)	return wsk;	return NULL;}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 %p\n\n", b, a, mystrstr(a, b));	printf("strchr:\t\t%s po raz pierwszy pojawia sie w %p\n\n", a, mystrchr(a, 'k'));	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;}