DS (RM) Program - Application : Disk Searching
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 | #include<iostream.h> #include<conio.h> #include<string.h> #include<fstream.h> void main() { char buf[80],str[15]; int i; const int MAX=80; clrscr(); ofstream out("test.txt"); if(!out) { cout<<"Can't open a file\n"; } cout<<"\n Enter 5 string : "; for(i=0;i<5;i++) { cin>>buf; out<<buf<<"\n"; } out.close(); ifstream in("test.txt"); cout<<"\nEnter string to search : "; cin>>str; while(in.good()) { in.getline(buf,MAX); //cout<<buf; if (strcmp(buf,str)==0) { cout<<"Match found ...\n"; break; } //cout<<buf<<endl; } if(in.eof()) cout<<"\nMatch not found ...."; in.close(); getch(); } |
Enter 5 string : jkl
abc
xyz
pqr
mnc
Enter string to search : mnc
Match found ...
