본문 바로가기

언어/C++

5장 4번- Ogdol -> Okdol 단어 알파벳 바꾸기

#include <iostream>
using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
char& find(char a[], char c, bool& success);

char& find(char a[], char c, bool& success){
	
	for(int i=0; i<sizeof(a); i++){
		if(a[i]==c){
			success=true;
			return a[i];
		}
	}
	return *a;
	
}


int main(int argc, char** argv) {
	
	
	char s[] = "Ogdol";
	bool b = false;
	char& loc = find(s, 'g', b);
	if( b == false) {
		cout << "g 발견할 수 없다" << endl;
		return 0;
	}
	loc = 'k';
	cout << s << endl;
	
	return 0;
}