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

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

Is aircel closed or closing down date... December 2017 news rumours

No, its nothing like that. There are some speculations amidst the Supreme court’s strict remarks but it doesn't seems like. They have also put in the application in the Apex Court for being heard their version as well and it looks like it will go through the rough patch as other party has put in the story as per their version and now they will get the chance to be heard. You will get to know that Aircel is operating and will keep on operating as it is on 3rd Feb, 2017 when the matter will be taken up in SC. Proof : 

Streamlining Java Web Application Deployment with React WAR Generator

In the ever-evolving world of web development, managing builds and deployments can often be cumbersome and error-prone. Today, we're excited to introduce a tool designed to simplify and streamline this process: the React WAR Generator . What is the React WAR Generator? The React WAR Generator is a Python-based tool that automates the creation of WAR (Web Application Archive) files for Java web applications. It caters specifically to frontend projects built with React or similar frameworks, making it easier to package and deploy your web applications to a Tomcat server. Key Features Profile-Based Builds : With support for multiple profiles ( dev , test , prod , default ), you can build your application according to different environments and configurations. Version File Generation : Optionally generate a version file that integrates versioning information directly into your TypeScript files, ensuring your build versions are always up-to-date. Tomcat Deployment : Simplify your deploy...

SEEDR : SAVIOUR OF TORRENT DOWNLOADING

Seedr is a next-generation product aiming to bring the torrent experience to a whole new level. Although torrents are not exactly legal or safe, but they have now become part and parcel of our online life now. So, to access them in the fastest and safest way possible we have Seedr. Features: Stream movies, music, and books on any device With top-in-class streaming technology, Seedr allows you to watch movies, listen to music, or read anything in your torrent library directly from the cloud on any device. Private and safe Seedr has high-level transport encryption to protect your privacy, and there is no need to worry about malware, viruses, or outside tracking – Seedr is the barrier protecting you. Very fast Seedr runs on a high-speed backbone and can fetch torrents to the cloud within several minutes down to several seconds. Fetch and stream torrents on your mobile device If you’ve ever tried using torrents on either tablet or phone, you’d quickly find out how impracti...

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

python program to take nested list input ...(nested list addition ,substraction etc)

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 #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue Mar 13 14:25:56 2018 @author: beast Note this program is for holding int value to list only """ def inmatrix (): matrixA = list () # intialize matrix as empty list try : row,col = [ int (j) for j in ( input ( "Enter the row and col " ) . split())] print (row,col) inp = "" except ValueError : print ( "Please Enter row and col seperated by space eg: 2 2" ) inmatrix() for i in range (row): for j in range (col): inp += (( input ( "Enter the number--->" )) + "," ) try : lst = [ int (a) for a in inp . split( "," ) if a != "" ] #delete int for making it to hold any data ...