0
#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;) //
}
3
Contributors
4
Replies
5
Views
10 Years
Discussion Span
Last Post by sarayaj
0

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.

0

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

0

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.

0
#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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.