In C++, Transform String Filled With Asterisks In Between

#include<iostream>
using namespace std;
int main(){
	const int MAX_INPUT = 20;
	const char EOC = '\0';
	char name[2 * MAX_INPUT];
	cout << "Enter name: ";
	cin.getline(name, MAX_INPUT);
	int i;
	for(i = 0; i < MAX_INPUT && EOC != name[i]; i++);
	int j = (i * 2)-1;
	i --;
	name[j--] = EOC;
	while(i){
		name[j--] = name[i--];
		name[j--] = '*';
	}
	cout << name << endl;
	return 0;
}
Download

Comments

Popular posts from this blog