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

Download pocket tank delux with 295 weapons free total 295 weapons version 1.6

Download Pocket Tanks Deluxe Full Version Free With 295 Weapons Pack | Size: 30MB UPDATED 2019 /19/april Description: Pocket Tanks is a 1-2 player computer game for Windows and Mac OS X, created by Blitwise Productions, developer of Super DX-Ball and Neon Wars. Adapted from Michael Welch's earlier Amiga game Scorched Tanks, this newer version features modified physics, dozens of weapons ranging from simple explosive shells to homing missiles, and the ability to move the tank. It supports several expansion packs. At the moment, players can have up to 295 different weapons total. Pocket Tanks is often abbreviated as PTanks. Have Fun! NOTE: FILE NAME IS SCRAMBLED FOR AVOIDING HARD DETECTION & FILE TAKEN DOWN . How to Play: Best with 2 players on the same computer at school or at work. UPDATED LINK https://mirr.re/d/u1Y https://nl26.seedr.cc/ff_get/447027537/ptd16.295.exe?st=lUp-PbRp4YOwToHIOGwStQ&e=1555747979 http://www.uploadmagnet.com/7gfzhbyfe...

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 Use Google for Hacking

Google serves almost 80 percent of all the search queries on the Internet, proving itself as the most popular search engine. However, Google makes it possible to reach not only the publicly available information resources, but also gives access to some of the most confidential information that should never have been revealed. In this post, you will find the information on how to use Google for exploiting security vulnerabilities that exists within many websites. The following are some of the ways to use Google for hacking : 1. Using Google to Hack Security Cameras: There exists many security cameras that are used for monitoring places like parking lots, college campus, road traffic etc. With Google, it is possible to hack these cameras so that you can view the images captured by them in real time. For this, all you have to do is just use the following search query in Google. Type in the Google search box exactly as given below and hit enter: inurl:”viewerframe?m...

QWERTY-keyboard when this idean came

QWERTY QWERTY   / ˈ k w ɜr t i /  is the most common modern-day  keyboard layout . The name comes from the first six  keys  appearing on the top left letter row of the keyboard and read from left to right: Q-W-E-R-T-Y. The QWERTY design is based on a layout created for the  Sholes and Glidden typewriter  and sold to  Remington  in 1873. It became popular with the success of the Remington No. 2 of 1878, and remains in use on electronic keyboards due to the  network effect  of a standard layout and a belief that  alternatives  fail to provide very significant advantages. [ 1 ]  The use and adoption of the QWERTY keyboard is often viewed as one of the most important case studies in  open standards  because of the widespread, collective adoption and use of the product. [ 2 ] History and purposes [ edit ] Keys are arranged on diagonal columns, to give space for the levers. Main article:  Sh...

Interesting Thing In Yahoo Logo

If you press "!" in the Yahoo logo on Yahoo.com Home page. You can hear group of girls saying "Yahooooo" !!! NOTE it doesnt work in yahoo india it works in yahoo US , type us.yahoo.com and try it

Dragon Age: Inquisition Digital Deluxe Edition + All DLCs (torrent) Repack Size: 20.1~23.9 GB

Brief : Dragon Age: Inquisition  is an  action role-playing video game  developed by  Bioware Edmonton  and published by  Electronic Arts . The third major game in the  Dragon Age  franchise,  Dragon Age: Inquisition  is the sequel to  Dragon Age: Origins  and  Dragon Age II . The game was released worldwide in November 2014 for  Microsoft Windows ,  PlayStation 3 ,  PlayStation 4 ,  Xbox 360 , and  Xbox One . Repack Size: 20.1~23.9 GB 

Mafia 2 PC Game Download Free ISO Full DLC

Mafia 2 PC Game Review: Mafia 2 Plaza free download game is first person shooting game released for pc and PlayStation 3. PC Game game mafia II is the second  Sequel of Mafia Series Launched  By Daniel Vávra in 2010. Mafia 2 is an open world map game. Just like  GTA IV For PC easy to install and run  on windows 10 64 bit. Game story is based on gang war in which the mafia runs the city and do all the crimes.  Gangs Run The City however  the player plays the important role in the game to be a cop in the game.Best weapons and New Graphics In mafia II Game For PC, World Wide Multiplayer Game For PC Play it online low system Requirements. PROOF :- Mafia 2 Complete Free Download. And find out the eve dance in the game. The game has been played by most of the Pro Games.The game can be played in Core 2 Duo mafia system requirements. Download Game for pc direct single link free.  Gta v download full game and install  it on pc. Mafi...

DOWNLOAD CODE BLOCKS 16.01 MINGW.SETUP .EXE 86.3 MB

Code::Blocks for Mac is a free C, C++ and Fortran IDE that has a custom build system and optional Make support. The application has been designed to be very extensible and fully configurable. Code::Blocks is an IDE packed full of all the features you will need. It has a consistent look, feel and operation across its supported platforms. It has been built around a plugin framework, therefore Code::Blocks can be extended with plugins. Support for any kind of functionality can be added by installing/coding a plugin. Key features include: Written in C++. No interpreted languages or proprietary libs needed.. Full plugin support. Multiple compiler support: GCC (MingW / GNU GCC), MSVC++, clang, Digital Mars, Borland C++ 5.5, and Open Watcom etc. Support for parallel builds. Imports Dev-C++ projects. Debugger with full breakpoints support. Cross-platform. Code::Blocks' interface is both customizable and extensible with Syntax highlighting, a tabbed interface, Class Br...