I am writing a program that should prompt the user to enter a line of text, and if there are consecutive spaces between the words, it should output the sentence with single spaces.
I'm not really even sure that I'm headed in the right direction, but even if I am, my code has a lot of errors.
Here's what I have:
Code:
int main(int argc, char **argv)
{
AnsiString; Line;
int Index;
Line = ReadStringPr("Enter your text with consecutive spaces." );
Index = 1;
while ((Index <= Length(Line) && Line[Index] == ' '))
{
if (Line[Index] != ' ')
{
WriteChar(Line[Index]);
Index = Index + 1;
}
else
{
WriteChar(' ');
while (Line[Index] == ' ')
Index = Index + 1;
}
}
getchar();
return 0;
}
And here are the errors:
C:\excredit5.cpp(3) : error C2065: 'AnsiString' : undeclared identifier
C:\excredit5.cpp(3) : error C2065: 'Line' : undeclared identifier
C:\excredit5.cpp(6) : error C2065: 'ReadStringPr' : undeclared identifier
C:\excredit5.cpp(10) : error C2065: 'Length' : undeclared identifier
C:\excredit5.cpp(10) : error C2109: subscript requires array or pointer type
C:\excredit5.cpp(13) : error C2109: subscript requires array or pointer type
C:\excredit5.cpp(16) : error C2065: 'WriteChar' : undeclared identifier
C:\excredit5.cpp(16) : error C2109: subscript requires array or pointer type
C:\excredit5.cpp(25) : error C2109: subscript requires array or pointer type
C:\excredit5.cpp(29) : error C2065: 'getchar' : undeclared identifier
Error executing cl.exe.
I know that the errors are probably pretty self-explanitory, but I really don't know how to fix them. Can anyone help?
Thanks so much.