cout<<" String to be cleaned: ";
fflush(stdin);
cin.getline(s, Size);
text = s;
for (int i = 0; i < strlen(s); i++)// entire string
{
if ((text[i] == ' ')||((int)text[i] == 9))
{
if((i = text.find(' ')) != string::npos)
{
text.erase(i, 1);
}
if((i = text.find('\t')) != string::npos)
{
text.erase(i,1);
text.insert(i,1, ' ');
}
}
}
cout<<" Cleaned string: "<<text<<endl<<endl;
ASKER
void cleanText()
{
char s[Size];
string text;
cout<<"String to be cleaned: ";
fflush(stdin);
cin.getline(s, Size);
text = s;
for (int i = 0; i < strlen(s); i++)// entire string
{
if ((text[i] == ' ')||((int)text[i] == 9))
{
if((i = text.find(' ')) != string::npos)
{
text.erase(i, 1);
}
if((i = text.find('\t')) != string::npos)
{
text.erase(i,1);
text.insert(i,1, ' ');
}
}
}
cout<<" Cleaned string: "<<text<<endl<<endl;
}
ASKER
ASKER
ASKER
void cleanText()
{
start:
system("cls");
char s[Size];
string text;
cout<<"String to be cleaned: ";
fflush(stdin);
cin.getline(s, Size);
text = s;
for (int i = 0; i < strlen(s); i++)// entire string
{
if (isspace(text[i]))
{
if((i = text.find(' ')) != string::npos)
{
text.erase(i, 1);
}
if((i = text.find('\t')) != string::npos)
{
text.erase(i,1);
text.insert(i,1, ' ');
}
}
}
cout<<" Cleaned string: "<<text<<endl<<endl;
}
ASKER
ASKER
void cleanSpaces(char *str) {
const char *strGet = str;
char *strSet = str;
while (*strGet) {
if (isspace(*strGet)) {
*strSet++ = ' ';
while (isspace(*(++strGet)));
}
else {
*strSet++ = *strGet++;
}
}
*strSet = '\0';
}
ASKER
C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.
TRUSTED BY