Skip to main content

C AND C++ program to find out a pattern within a String

This program takes an input string From user and tell if the given string is present in the String or not

Example: This is always true
pattern-> is 

output -> pattern found 

and if pattern input -> zxc
output -> No match found 
NOTE: CODE:: BLOCKS IS USED in editing and compiling the source code ....


+++++++++++++++++++++++++++++C Source Code ++++++++++++++++++++++++++++++

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

void main ()

{
char str[999],pattern[999];
int flag=0,i,j=0,loc;

printf("Enter the string \n");
gets(str);
printf("Enter the string to find pattern\n");
gets(pattern);
for(i=0;str[i]!='\0';i++)
{ /// main for loop
    if(flag==1) break;

    if(str[i]==pattern[0])
    {/// a match is found
        i++;
        flag=1;
loc=i;
        for( j=1;pattern[j]!='\0';j++)
        {
            if(str[i]!=pattern[j])
            {

            flag=0;
            break;
            }// end if
else
{

    flag=1;


}

        i++;
        }// end further check for

    } /// a match is found end if


}/// main for loop

 if(flag==0)
 printf("\n\t\t+++++++++++++++++++++++++++++++++++++++++++\n\t\t\t\tNo match found \n\t\t+++++++++++++++++++++++++++++++++++++++++++ \n");
else
  {

   printf("\n\t\t+++++++++++++++++++++++++++++++++++++++++++\n\t\t   pattern is present from location %d\n\t\t+++++++++++++++++++++++++++++++++++++++++++ \n",loc);

  }


getch();




}



+++++++++++++++++++++++++++++END C SOURCE CODE +++++++++++++++++


++++++++++++++++++C++ SOURCE CODE +++++++++++++++++++++++++++++++++



#include <iostream>
#include <conio.h>
using namespace std;
int main ()

{
char str[999],pattern[999];
int flag=0,loc;

cout<<"Enter the string \n";
cin.getline(str,999);
cout<<"Enter the string to find pattern\n";
cin.getline(pattern,999);
for(int i=0;str[i]!='\0';i++)
{ /// main for loop
    if(flag==1) break;

    if(str[i]==pattern[0])
    {/// a match is found
        i++;loc=i;
        flag=1;

        for(int j=1;pattern[j]!='\0';j++)
        {
            if(str[i]!=pattern[j])
            {

            flag=0;

            break;
            }// end if
else
{

    flag=1;


}

        i++;
        }// end further check for

    } /// a match is found end if


}/// main for loop

 if(flag==0)
 cout<<"\n\t\t+++++++++++++++++++++++++++++++++++++++++++\n\t\t\t\tNo match found \n\t\t+++++++++++++++++++++++++++++++++++++++++++ \n";
else
    cout<<"\n\t\t+++++++++++++++++++++++++++++++++++++++++++\n\t\t   pattern is present :from location "<<loc<<"\n\t\t+++++++++++++++++++++++++++++++++++++++++++ \n";

getch();




}


+++++++++++++++++++++++ END C++ SOURCE CODE +++++++++++++++++++++


Comments

Popular posts from this blog

USE any TRIAL SOFTWARE FOREVER WITHOUT SERIAL NUMBER

USE any TRIAL SOFTWARE FOREVER WITHOUT SERIAL NUMBER(most wanted trick) Run a trial software forever now with time stopper you can run a trial software forever no need to fetch for serial numbers,activation codes,patch just DOWNLOAD TIME STOPPER now open it install it click browse select the .exe of the software or file which you want to run forever now simply click create desktop icon and now delete all its existing shortcuts now have fun enjoying software for life time

C++ Program to Find HCF and LCM among 4 numbers (Easiest Logic)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 #include <iostream> #include <math.h> using namespace std; int main () { int a,b,c,d,i,j,minimum; cout << "Enter the all four number " ; cin >> a >> b >> c >> d; if (a < b && a < c && a < d) minimum = a; else if (b < c && b < d) minimum = b; else if (c < d) minimum = c; else minimum = d; for (j = minimum;; -- j) { if (a % j == 0 && b % j == 0 && c % j == 0 && d % j == 0 ) { break ; } } for (i = 1 ;;i ++ ) { if (i % a == 0 && i % b == 0 && i % c == 0 && i % d == 0 ) break ; } cout << "Lowest Common factor=>" << i << endl; ...

python program to Print Starting Series OF Indian Mobile Number for a State or operator or both

import requests import urllib.request import time from bs4 import BeautifulSoup as bs import re url = ' https://en.wikipedia.org/wiki/Mobile_telephone_numbering_in_India' state_to_extract = "UE" #if set to None all state is considered telecom_to_extracted = None #if set to none all operator from particular city is extracted response = requests . get(url) print (response) soup = bs(response . text, "html.parser" ) one_a_tag = soup . findAll( 'tr' )[ 35 :] lst = [] for k in one_a_tag: s = k . findAll( 'td' ) limit = len (s) i = 0 while True : if i == limit: break no = s[i] . text i += 1 if i == limit: break operator = s[i] . text i += 1 if i == limit: break state = s[i] . text i += 1 if i == limit: break res = f "{no} {operator} {state}" if state_to_extract is None : if telecom_to_extracted is None : lst . append(no) elif telecom_to_e...

C Program to Sort Elements in Lexicographical Order (Dictionary Order)

#include #include int main () { int i , j ; char str [ 10 ][ 50 ], temp [ 50 ]; printf ( "Enter 10 words:\n" ); for ( i = 0 ; i < 10 ; ++ i ) scanf ( "%s[^\n]" , str [ i ]); for ( i = 0 ; i < 9 ; ++ i ) for ( j = i + 1 ; j < 10 ; ++ j ) { if ( strcmp ( str [ i ], str [ j ])> 0 ) { strcpy ( temp , str [ i ]); strcpy ( str [ i ], str [ j ]); strcpy ( str [ j ], temp ); } } printf ( "\nIn lexicographical order: \n" ); for ( i = 0 ; i < 10 ; ++ i ) { puts ( str [ i ]); } return 0 ;   }  https://www.jdoodle.com/embed/v0/c/gcc-5.3.0/6WK

Binary Search Tree in C++( dynamic memory based )

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 #include<bits/stdc++.h> using namespace std; struct bst { int val; bst * left, * right; }; bst * root = nullptr; void srch ( int num,bst * head) { if (head == nullptr){ cout << " \n Number is not present \a " << endl; return ; } if (head -> val == num) { cout << " \n Number is present \n\a " ; return ; } else { if (num < head -> val) srch(num,head -> left); else srch(num,head -> right); ...

How to Detect Anonymous IP Addresses

Proxy Detection Serviceshttp = So in order to stop such online frauds, Proxy Detection has become a critical component. Today most companies, credit card merchants and websites that deal with e-commerce transactions make use of Proxy Detection Services like MaxMind and FraudLabs to detect the usage of proxy or spoofed IP from users participating online. Proxy Detection web services allow instant detection of anonymous IP addresses. Even though the use of proxy address by users is not a direct indication of fraudulent behaviour, it can often indicate the intention of the user to hide his or her real IP. In fact, some of the most used ISPs like AOL and MSN are forms of proxies and are used by both good and bad consumers. How Proxy Detection Works? Proxy detection services often rely on IP addresses to determine whether or not the IP is a proxy. Merchants can obtain the IP address of the users from the HTTP header on the order that comes into their website . This IP addr...

12 Tips to Maintain a Virus Free Computer

1. Email is one of the common ways by which your computer can catch a virus . So it is always recommended to stay away from SPAM. Open only those emails that has it’s origin from a trusted source such as those which comes from your contact list. If you are using your own private email host (other than gmail, yahoo, hotmail etc.) " then it is highly recommended that you use a good anti-spam software. And finally NEVER click on any links in the emails that comes from untrusted sources. 2. USB thumb/pen drives is another common way by which viruses spread rapidly." So it is always a good habit to perform a virus scan before copying any data onto your computer. NEVER double-click the pen drive to open it. Instead right-click on it and select the option “open”. This is a safe way to open a pen drive. 3. Be careful about using MS Outlook. Outlook is more susceptible to worms than other e-mail programs, unless you have efficient Anti-Virus programs running. Use Pegasus ...