Hazır Script – Hazır Kod » Dosyadaki kelimeyi bulma

Haberler  Forum  Memurlar  Meb  Sağlık   Sözleşmeli  Kpss  Adalet  Diyanet   Kariyer  Anket  Spor  Sözlük  Oyun  Sohbet  FM

 

Dosyadaki kelimeyi bulma

Dosyadaki kelimeyi bulma

Windows/ara tarzinda yazilmis bir program. girilen kelimeyi,belirtilmis dosya çinde arama

codeDivStart()


#include<iostream>

#include<cctype>

#include<string>

#include<fstream>

using namespace std;

int main(){

	string inbuff,search_key;								//a strings which holds the data and search key

	int sk_size,ib_size,space1=0,space2=0,counter,check=0,mm=0;

	ifstream fin( "dosyanın bulunduğu yer/dosya_adi.uzantısı" );

	if ( !fin ){											// opened successfully?

		cout<<"File Couldn't Found\nProgram Executed\n";

		return false;										// if not, return false

	}

	else{											//else give a msj and save the input

		cout<<"Your File Opened Succesfully\n";

		getline(fin,inbuff);

	}

	cout<<"Usage Of The Program:\n"

		<<"*search_key --> finds the words that ends with search_key\n"

		<<"search_key* --> finds the words that starts with search_key\n"

		<<"? --> u can use it for one forgetten character in your searchkey\n"

		<<"----------------------------------------------------------------\n"

		<<"Type - to end to program\n";

	cin>>search_key;

	sk_size=search_key.size();//holds the size of the search_key

	ib_size=inbuff.size();//holds the size of the inbuff

	if(search_key[0]=='-'){

		cout<<"\nProgram Will now terminated\n";

		return 0;

	}

	else if(search_key[0]=='*'){//is it start with *

		for(int i=0;i<ib_size;i++){//loop for general inbuff

			space1=i;

			if(inbuff[i]==' '){//checks whether the character is equal to ' '

				for(int j=(sk_size-1);j>0;j--){//loop for finding

					if(search_key[j]==inbuff[space1-1] || search_key[j]=='?' || static_cast<int>(search_key[j]+32)==inbuff[space1-1] || static_cast<int>(search_key[j]-32)==inbuff[space1-1]){

						space1--;

						counter++;

						continue;

					}

					else{

						space2=space1+counter;

						break;

					}

				}

				space1=space1+counter;

			}

			if(counter==sk_size-1){//checks whethet finded

					while(space2!=space1){//yes,print it

						cout<<inbuff[space2];

						space2++;

					}

					cout<<endl;

			}

			counter=0;

		}//end of loop for general inbuff

	}

	else if(search_key[sk_size-1]=='*'){

		cout<<"\nSearch Started...\n";

		for(int i=0;i<ib_size;i++){//loop for general inbuff

			space1=i;

			if(inbuff[i]==' '){//checks whether the character is equal to ' ' or at the start point

				for(int j=0;j<sk_size-1;j++){

					if(inbuff[space1+1]==search_key[j] || search_key[j]=='?' || static_cast<int>(search_key[j]+32)==inbuff[space1+1] || static_cast<int>(search_key[j]-32)==inbuff[space1+1]){

						counter++;

						space1++;

						continue;

					}

					else{

						space2=space1-counter;

						break;

					}

				}

				space1=space1-counter;

				if(counter==sk_size-1){

					while(inbuff[space1+1]!=' '){

						cout<<inbuff[space1];

						space1++;

					}

					cout<<inbuff[space1]<<endl;;

				}

				counter=0;

			}

		}//end of loop fpr general inbuff

	}

	else if(search_key[sk_size-1]!='*'&&search_key[0]!='*'){

		search_key[sk_size]='x';

		sk_size++;

		cout<<"\nSearch Started...\n";

		for(int i=0;i<ib_size;i++){//loop for general inbuff

			space1=i;

			if(inbuff[i]==' '){//checks whether the character is equal to ' ' or at the start point

				for(int j=0;j<sk_size;j++){

					if(inbuff[space1+1]==search_key[j] || search_key[j]=='?' || static_cast<int>(search_key[j]+32)==inbuff[space1+1] || static_cast<int>(search_key[j]-32)==inbuff[space1+1]){

						counter++;

						space1++;

						continue;

					}

					else{

						space2=space1-counter;

						break;

					}

				}

				space1=i;

				if(counter==sk_size-1 && inbuff[space1+counter+1]==' '){

					while(inbuff[space1+1]!=' '){

						cout<<inbuff[space1];

						space1++;

					}

					cout<<inbuff[space1]<<endl;;

				}

				counter=0;

			}

		}//end of loop fpr general inbuff

	}

	return 0;

}
Etiketler:
Henüz yorum yok.

HABERLER

Bad Behavior has blocked 46 access attempts in the last 7 days.