[ create a new paste ] login | about

Link: http://codepad.org/MuX0UruP    [ raw code | output | fork ]

nel - C, pasted on Oct 10:
#include <stdio.h>

char *mystrstr(char *input, char *match);

int main(void)
{
	char *temp; //
	char input[] = "Hello, dude.";
	char match[] = "dude";

	if((temp = mystrstr(input, match))==NULL) {
		printf("not matched.");
	}

	else printf("%s", temp);

	return 0;
}

char *mystrstr(char *input, char *match)
{
	char *start, *p1, *p2;

	p1 = match;

	for(start=&input[0]; start!='\0'; start++) 
	{
		p2 = start;

		while(p1!='\0') 
		{
			if(*p1!=*p2) break; // different chars
			*p1++;
			*p2++;
		}

		if(*p1=='\0') return start;

	}

	return NULL;
}


Output:
1
dude.


Create a new paste based on this one


Comments: