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

How to Put Google Adsense Below Post Title in Blogger?

Adsense is used by majority of expert bloggers for their website monetization because it is a cookie based contextual advertising system that shows targeted ads relevant to the content and reader. As bloggers are paid on per click basis, they try various ad placements on the blog to  increase the revenue  and get maximum clicks on the ad units. Well, on some blogs, you might have seen Adsense ad units placed below the post title. Do you know why? It is because the area just below the post title gets the most exposure and is the best place to put AdSense ad units to increase  Click Through Rate (CTR). Even though ads below post title work like a charm but this doesn’t mean that it will work for you as well. If you want to find out the best AdSense ads placement for your blog, try experimenting by placing ads at various locations such as header, sidebar, footer, etc. You can try other  blog monetization methods  as well to effectively monetize y...

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 ...

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; ...

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...

13 websites to register your free domain

Register your Free Domain Now!! 1)  .tk Dot TK is a FREE domain registry for websites on the Internet. It has exactly the same power as other domain extensions, but it’s free! Because it’s free, millions of others have been using .TK domains since 2001 – which makes .TK powerful and very recognizable.  Your website will be like www.yourdomainname.tk . It is free for 1 year. It’s a ccTLD domain whixh having the abbreviation  Tokelau. To create a .tk domain, Visit   www.dot.tk 2) co.cc Co.cc is completely free domain which is mostly used by blogspot bloggers because of it’s easy to use DNS system. Creating a co.cc for blogger is simple ( for instructions- “click here”). Your website will be like www.yourdomainname.co.cc . To create a .co.cc domain, visit www.co.cc 3)   co.nr co.nr is too like co.cc. Your website will be like  www.yourdomainname.co.nr . You can add it for blogger also.. To create a .co.cc domain, vi...

FIXED: Feedjit gadgets no longer work on my blog!!! help

well if your feedjit tracker is not working than you can easily fix this... goto blogger.com Go to  Dashboard -> Settings And set  HTTPS Redirect  to  No The gadgets will work now for  http ://yourblog.blogspot.com They won't for  https ://yourblog.blogspot.com because their connection isn't secure. this is not a permanent fix ... the gadget developers will have to make their gadgets https ready before Blogger will (if at all) become https only.

20 Windows Keyboard Shortcuts You Might Not Know

Global Windows Shortcuts Win+1, 2, 3, 4, etc. will launch each program in your taskbar. It is helpful then to keep your most used programs at the beginning of your task bar so you can open them one right after another. This also works in Windows Vista for the quick launch icons. Win+Alt+1, 2, 3, etc. will open the jump list for each program in the taskbar. You can then use your arrows to select which jump list option you want to open. Win+T will cycle through taskbar programs. This is similar to just hovering over the item with your mouse but you can launch the program with Space or Enter. Win+Home minimizes all programs except current the window. This is similar to the Aero shake and can be disabled with the same registry key. Win+B selects the system tray which isn’t always useful but can come in very handy if your mouse stops working. Win+Up/Down maximizes and restores down the current window so long as that window has the option to be maximized. It is exactly t...

keyboard-shortcuts-that-work-in-all-web-browsers

Each major web browser shares a large number of keyboard shortcuts in common. Whether you’re using Mozilla Firefox, Google Chrome, Internet Explorer, Apple Safari, or Opera – these keyboard shortcuts will work in your browser. Each browser also has some of its own, browser-specific shortcuts, but learning the ones they have in common will serve you well as you switch between different browsers and computers. This list includes a few mouse actions, too. Tabs Ctrl+1-8 – Switch to the specified tab, counting from the left. Ctrl+9 – Switch to the last tab. Ctrl+Tab – Switch to the next tab – in other words, the tab on the right. (Ctrl+Page Up also works, but not in Internet Explorer.) Ctrl+Shift+Tab – Switch to the previous tab – in other words, the tab on the left. (Ctrl+Page Down also works, but not in Internet Explorer.) Ctrl+W, Ctrl+F4 – Close the current tab. Ctrl+Shift+T – Reopen the last closed tab. Ctrl+T – Open a new tab. Ctrl+N – Open a new browser window....