#include <iostream.h>
#include <conio.h>
char *mystrstr(char *,char *);
void main(void)
{
clrscr();
char *str1,*str2;
str1 = new char[100];
str2 = new char[100];
cout << "Enter first string: ";
cin.get(str1,99);
cin.get();
cout << "Enter seconed string: ";
cin.get(str2,99);
cin.get();
cout << mystrstr(str1,str2);
getch();
}
char *mystrstr(char *s1,char *s2)
{
// my code in this block is wrong//
// Please help me;) //
}

First things first...post your code in code tags as the background image in which you write your post says. Read the forum announcements for more details.

Dont use void main( void ). This is the wrong defination of main( ) . It actually is int main( ).

Post the specifications -- ie the compiler and the OS you are using.

Post the code which you have in your function.

at the first, thank you very much
my os is Windows XP
I'm using Borland C++ 5.02

But where is the code which you attempted and which is not working...

Paste it here and let me have a look at your own function.

#include<iostream>
using namespace std;


const char* MyStrStr(const char* searchStr, const char* needle)
{
	unsigned int count=0;
	unsigned int lenNeedle = 0;
	while(needle[lenNeedle]!='\0')
		lenNeedle++;
	unsigned int i = 0; 
	unsigned int j = 0;
	while(searchStr[i]!='\0')
	{
		while(needle[j]!='\0')
		{
			if(needle[j]==searchStr[i])
			{	count++;
				j++;
				if(count == lenNeedle)
					return (&searchStr[i] - lenNeedle + 1);
				break;
			}
			else 
			{
				j = 0;
				count=0;
				break;
			}
		}
		i++;
	}
	return NULL;
}



int main()
{
	char* haystack = "Hey you!";
	char* needle = "yo";
	printf("%s\n", MyStrStr(haystack, needle));

	return 0;
}
//output: "you!"
#include <iostream.h>
#include <conio.h>
char *mystrstr(char *,char *);
void main(void)
{
clrscr();
char *str1,*str2;
str1 = new char[100];
str2 = new char[100];
cout << "Enter first string: ";
cin.get(str1,99);
cin.get();
cout << "Enter seconed string: ";
cin.get(str2,99);
cin.get();
cout << mystrstr(str1,str2);
getch();
}
char *mystrstr(char *s1,char *s2)
{
// my code in this block is wrong//
// Please help me;) //
}
This article has been dead for over six months. Start a new discussion instead.