Write a C++ program that takes five alphabets from the user and ask the user to delete any
alphabet. You should store the alphabets in a char array.
#include <iostream>
using namespace std;
char* Delete(char* str, char c)
{
char* res = new char[strlen(str) - 1];
int j = 0;
for (int i = 0; i < strlen(str); i++)
{
if (str[i] != c)
res[j++] = str[i];
}
res[j] = '\0';
return res;
}
int main()
{
char alph[6];
cout << "Please, enter membsers of alphabet: ";
for (int i = 0; i < 5; i++)
{
cin >> alph[i];
}
alph[5] = '\0';
char del;
cout << "Please, enter an alphabet to delete: ";
cin >> del;
char* res = Delete(alph, del);
cout << "Resulting alphabet is : ";
for (int i = 0; i < strlen(res); i++)
{
cout<<res[i]<<" ";
}
}
Comments
Leave a comment