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.

You didn't post the include file(s) -- you DID include the headers for AnsiString didn't you ?????

line 3: remove the semicolon between AnsiString and Line.

line 6: you have to declare all functions before they can be used. If the function is not coded before the function in which it is used, then you must prototype it. Put this above line 1 (above main()) AnsiString ReadStringPr(const char* prompt); line 10: where is Length declared?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.