Click to See Complete Forum and Search --> : Why does this code not Work!!!


TerraNova
May 23rd, 2003, 04:11 AM
Can anyone help with the following code and tell me why It will not work, banging head several times a minute against walls - sorry might be easy for some but new to this!!!

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

#include <vcl.h>
#pragma hdrstop
#include "MT262io.h"

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

#pragma argsused

// Prototypes for the two functions
bool ValidName(AnsiString Name);
void ReplaceSpace(AnsiString &InString, char NewChar);
// ---------------------------------------
int main(int argc, char* argv[])
{

AnsiString Text;

Text = ReadStringPr("Enter Text: ");


if (ValidName(Text))
WriteStringCr("String Accepted");
else
ReplaceSpace(Text, '*');
if (ValidName(Text))
{
WriteStringCr("String Contains space characters.. ");
}

WriteStringCr("Illegal String");


getchar();
return 0;
}
//---------------------------------------------------------------------------


bool ValidName(AnsiString Name)
{
int I = 0;
int Count = 0;
bool valid;

if ((Name[I]>='A')&&(Name[I]<='Z'))
for (I = 0; I <= Length(Name) && (Count < 9); Count = Count + 1,I = I + 1)
if (Name[I] != ' ')
Count = Count + 1;
else
valid = false;
return valid;
}
//-------------------------------------------------------------------------

void ReplaceSpace(AnsiString &InString, char NewChar)
{
int Index;

for (Index = 1 ; Index < 9 ; Index = Index + 1 )
if (InString[Index] == ' ')
InString[Index] = NewChar;
}


If anyone can assist would be very gratefull

Kindest Regards
Brian