I am writing a program that prompts a user to enter a line of text, and if there are consecutive blank spaces in the sentence, it will replace those with just one space.
Here is the code:
int main(int argc, char **argv)
{
AnsiString; Line;
int Index;
Line = ReadStringPr("Enter a line of text: " );
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;
}
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.
There are a lot of errors and I know that they are probably self-explanitory, but I do not know how to fix them. Can anyone help?
Thanks a lot.