C++ Program for Search And Replace in A String
#include<iostream> #include<iomanip> #include<string.h> using namespace std; void line() { cout<<"========================================\n"; } void stringprogram() { int i,n,len=0,g=0; char arr[20],ch,ch1=0; line(); cout<<"String Programs #18\n"; line(); cout<<"Enter Any values to the String :"; cin.getline(arr,20); line(); for(n=0;arr[n]!='\0';n++); cout<<"Enter Whatever you want to search :"; cin>>ch; cout<<"Enter Whatever you want to replace :"; cin>>ch1; for(i=0;i<n;i++) { if(arr[i]==ch) { arr[i]=ch1; len++; } } if(len==0) cout<<"number not found..."; cout<<arr<<" "; } int main() { stringprogram(); }