#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>

int strcompare(char *, char *);
void strcopy(char *, char *);
void strconcatenate(char *, char *);
int strlength(char *);
int strfindchr(char *, char);
int strfindstr(char *, char *);

void main()
{
 char a[100], b[100], ch, str[100];
 cout<<"\nEnter String 1: ";
 gets(a);
 cout<<"Enter String 2: ";
 gets(b);
 if(strcompare(a, b) == 1)
 {
  cout<<"\nTwo Strings are equal";
 }
 else
 {
  cout<<"\nTwo Strings are not equal";
 }
 strcopy(a, b);
 cout<<"\nFirst String after Copy: "<<a;
 strconcatenate(a, b);
 cout<<"\nFirst String after Concatenation: "<<a;
 cout<<"\nLength of First String: "<<strlength(a);
 cout<<"\n\nEnter a Character : ";
 cin>>ch;
 if(strfindchr(a, ch) == NULL)
 {
  cout<<ch<<" not found";
 }
 else
 {
  cout<<ch<<" is found at position "<<strfindchr(a, ch);
 }
 cout<<"\n\nEnter a String : ";
 cin>>str;
 if(strfindstr(a, str) == NULL)
 {
  cout<<str<<" not found";
 }
 else
 {
  cout<<str<<" is found at position "<<strfindstr(a, str);
 }
}

int strcompare(char *a, char *b)
{
 int equal = 1, i=0;
 if(strlength(a) != strlength(b))
 {
  return 0;
 }
 while(*(a+i) != '\0')
 {
  if(*(a+i) != *(b+i))
  {
   equal = 0;
   break;
  }
  i++;
 }
 return equal;
}

void strcopy(char *a, char *b)
{
 int i=0;
 while(*(b+i) != '\0')
 {
  *(a+i) = *(b+i);
  i++;
 }
 *(a+i) = '\0';
}

void strconcatenate(char *a, char *b)
{
 int i=0, j=0;
 while(*(a+i) != '\0')
  i++;
 while(*(b+j) != '\0')
 {
  *(a+i) = *(b+j);
  i++;
  j++;
 }
 *(a+i) = '\0';
}

int strlength(char *a)
{
 int len=0, i=0;
 while(*(a+i) != '\0')
 {
  i++;
  len++;
 }
 return len;
}

int strfindchr(char *a, char b)
{
 int found=0, i=0;
 while(*(a+i) != '\0')
 {
  if(*(a+i) == b)
  {
   found = 1;
   break;
  }
  i++;
 }
 if(found == 0)
  return NULL;
 else
  return i+1;
}

int strfindstr(char *a, char *b)
{
 int found=0, i=0, j=0, pos;
 while(*(a+i) != '\0')
 {
  found = 1;
  if(*(a+i) == *(b+j))
  {
   pos = i+1;
   while(*(b+j) != '\0')
   {
    if(*(a+i) != *(b+j))
    {
     found = 0;
     goto out;
    }
    i++;
    j++;
   }
   goto out;
  }
  found=0;
  i++;
 }
 out:
 if(found == 0)
  return NULL;
 else
  return pos;
}