Hi all, I'm having some serious problems with a peice of work i've been asked to do from a given design. I have been given the following .h file to use instead of C/C++'s standard header files..

Code:
#ifndef MT262ioH
#define MT262ioH
#define VCL_IOSTREAM
#include <vcl.h>
#include <stdio.h>
#include <conio.h>
//---------------------------------------------------------------------------
//The first pool of functions Write out values of standard types
//with or without accompanying message (Pr) and with or without
//following carriage return (Cr). Conventions should be self explanatory.

void WriteStringPrCr(AnsiString Prompt, AnsiString Name);
void WriteStringPr(AnsiString Prompt, AnsiString Name);
void WriteStringCr(AnsiString Prompt);
void WriteString(AnsiString Prompt);
void WriteIntPrCr(AnsiString Prompt, int N);
void WriteIntPr(AnsiString Prompt, int N);
void WriteIntCr(int N);
void WriteInt(int N);
void WriteCharPrCr(AnsiString Prompt, char Ch);
void WriteCharPr(AnsiString Prompt, char Ch);
void WriteCharCr(char Ch);
void WriteChar(char Ch);
void WriteFloatPrCr(AnsiString Prompt, float X);
void WriteFloatPr(AnsiString Prompt, float X);
void WriteFloatCr(float X);
void WriteFloat(float X);
void WriteDoublePrCr(AnsiString Prompt, double X);
void WriteDoublePr(AnsiString Prompt, double X);
void WriteDoubleCr(double X);
void WriteDouble(double X);
//------------------------------------------------------------
//Next pool are corresponding Read functions
AnsiString ReadStringPr(AnsiString Prompt);
AnsiString ReadString(void);
int ReadIntPr(AnsiString Prompt);
int ReadInt(void);
char ReadCharPr(AnsiString Prompt);
char ReadChar(void);
float ReadFloatPr(AnsiString Prompt);
float ReadFloat(void);
double ReadDoublePr(AnsiString Prompt);
double ReadDouble(void);
//-----------------------------------------------------
//One other useful function needed in Block I.
int Length(AnsiString AString);
//-------------------------------------------------------
#endif

From that I have been asked to write a program that will remove ALL spaces from a program... So far I have this..

Code:
#include <vcl.h>
//Question Asking Assignment by Simon Taylor 2004
//TMA01 Part 2, Question 3 A

#include "MT262io.h"
#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused
int main(int argc, char* argv[])
{

        //Setup Variables
        int Index;
        String Line;

        //1.1    Write Prompt
        WriteString("Enter your text. It must not finish with a space character");

        //1.2    Get String with spaces
        Line = ReadStringPr(":");

        //1.3    Set Index to 1
        Index = 1;

        //2.1
        while(Index <= Length(Line))
        {
                //3.1   Test position for a space
                if(Line[Index] != ' ')
                {
                        //3.2.1     If space not found write the character
                        WriteString(Line[Index]);
                        //3.2.2     and incriment counter
                        Index = Index + 1;
                }
                //3.3    if space found
		else
		{
                        //3.4.1     write a single space
			WriteString(" ");
                        //3.4.2      loop while other spaces found
                        while(Line[Index] == ' ')
			{
                                //3.4.3    add to the index thus removing
				Index = Index + 1;
			}//3.4.4      loopend

		}//3.5      ifend

        }//4       loopend

        getchar();
        return 0;
}
If you compile and run the above you will notice it cannot remove spaces from the start or the end of the string. Does anyone have any suggestions/areas I could research to find the answer?

Thanks in advance for any help.

Regards
Sy