Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* This Program is for String Finder . i.e : Write a program that takes a string from user and search a word in the string. The program Prints position of 1st and last letter of the word in the string if it finds the word !!!! */
- // For more scripts and tricky stuff visit : www.tigerzplace.com
- //Program Code:
- #include <iostream>
- #include <conio.h>
- using namespace std;
- int search(char str[], char sbstr[])
- {
- int subl,strl;
- for (int x=0;str[x]!='\0';x++)
- {
- strl=x;
- }
- for (int y=0;sbstr[y]!='\0';y++)
- {
- subl=y;
- }
- int c=0,f=0,l=0,cnt=-1;
- for(int s=c;s<=strl;s++)
- {
- if(sbstr[c]==str[s])
- {
- if (c==0 || c==subl)
- {
- switch(c)
- {
- case 0:
- f=s+1;
- break;
- default:
- l=s+1;
- break;
- }
- }
- cnt++;
- c++;
- }
- }
- if(cnt==subl)
- {
- cout << "SubString Found!!!\n";
- cout << "Location First : "<<f;
- cout << "\nLocation last :"<<l;
- }else{
- cout << "SubString Not found !!!! \n";
- }
- getch();
- }
- int main()
- {
- char str[50],sbstr[48];
- cout << "\t\tSub String Finder\n\n";
- cout << "NOTE::::: Spaces are not allowed !!! ";
- cout << "\nEnter Your String : ";
- cin >>str;
- cout << "\nEnter the substring you want to find :";
- cin>>sbstr;
- search(str,sbstr);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement