Sunday, 26 May 2013

0 A C - PROGRAM FOR MATCH ANY CHARACTER BETWEEN TWO ENTERED STRINGS (WORDS)

MATCH STRING 
THIS IS A PROGRAM TO MATCH ANY CHARACTER OF TWO ENTERED STRING (WORDS) AND DISPLAY THE POSITION (FIRST POSITION) OF THE CHARACTER MATCHED FROM THE 1ST ENTERED STRING.


THE PROGRAM IS :
#include<stdio.h>
#include<stdio.h>
int matchany(char [],char []);
void main()
{
    int pos;
    char s1[20],s2[20];
    printf("Enter the first string \n");
    gets(s1);
    printf("Enter the second string \n");
    gets(s2);
        pos=matchany(s1,s2);
        printf("\n The first string is %s \n",s1);
        printf("\n The second string is %s \n",s2);
        if(pos==-1)
        {
            printf("\n no character of %s is present in %s \n",s1,s2);
        }
        else
        {
            printf("\n the match letter in %s is at position = %d \n",s1,pos);
        }
        getch();
}
        int matchany(char s1[],char s2[])
        {
            int i,j;
            for(i=0;s1[i]!='\0';i++)
            {
                for(j=0;s2[j]!='\0';j++)
                {
                    if(s1[i]==s2[j])
                    {
                        return (i+1);
                    }
                }
            }
            return -1;
        }
 



Just copy and paste into your Microsoft Visual C++ or Turbo C (these are program developing software) 
Or else you can try this demo file and use it ... 
Click HERE to download this file. 
(Press ctrl+z and hit Enter to end the program).. 
~NOTE~ : While executing if you get any warning then just ignore it and continue with your program... 


IF FACE ANY PROBLEM DON'T FORGET TO COMMENT ...!!

Don't Forget to share.... 

Follow on Facebook : Ethical Hacking.

No comments:

Post a Comment