Write a program that skips blanks in the input and prints the input text with no blanks at all.
So, for the input: Once there was a tree
The output would be: Oncetherewasatree
You should skip ALL the white spaces including tabs, if they appear in the input line.
This is what I have so far:
char* LeftTrim (char* const szTrim)
{
long lSpaceCount;
for (lSpaceCount = 0; *(szTrim + lSpaceCount) == ' '; ++lSpaceCount);
long lNextChar;
for (lNextChar = 0; *(szTrim + lSpaceCount + lNextChar - 1) != '\0';
*(szTrim + lNextChar) = *(szTrim + lNextChar + lSpaceCount), ++lNextChar);
return szTrim;
}
char* RightTrim (char* const szTrim)
{
long lSpaceCount;
for (lSpaceCount = lstrlen (szTrim) - 1; *(szTrim + lSpaceCount) == ' '; --lSpaceCount);
*(szTrim + lSpaceCount + 1) = '\0';
return szTrim;
}
#define TRIM(x) LeftTrim (RightTrim (x))
The problem is that I do not know how to make it to where anyone can input a text and it will return it with no spaces. Please help!!
C++ Programming Help!!?
here is the code to store the string without the spaces into a new variable...
for (i=0; sentence[i]!='\0';)
{
if (isalpha(sentence[i]))
nospace[j++]=sentence[i++];
else
i++;
}
nospace[j]='\0';
//variable string is the original text
/*nospace is the string without the spaces or any other special characters...*/
Reply:lookup the string tokenizer in the C++ libraries. Tokenize the input string by spaces ( " " ) and cycle through the tokenizer printing each word... that'll do it.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment