I have written this code to swap the characters between the asterisks when a * is detected however it does not seem to work. Anyone? Take for example an input string "This is *swaped* here no change" will produce an output string " This is *depaws* here no change". Thanks.
Code:
#include <vcl.h>
#include "MT262io.h"
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
// Any declarations you require go here.
AnsiString Sentence,Sentence1,Sentence2;
int index,index1,Endindex;
bool swap;
// Your code goes here.
index=1,index1=1,Endindex=1;
swap=true;
Sentence=ReadStringPr("Enter text to be tested.");
while(index<=Length(Sentence))
{
if(swap==false)
{
Sentence1[index]=Sentence[index];
index=index+1;
}
if(Sentence[index]=='*')
{
while(Sentence[index1]!='*')
{
index1=index1+1;
}
swap=true;
}
if(swap==true)
{
for(index=1; index<=10; index++)
{
Sentence[index]=Sentence2[Endindex];
Endindex=Endindex-1;
}
swap=false;
}
}
WriteString(Sentence1);
WriteString(Sentence);
Sentence.Insert(Sentence2,'*'+1);
getchar();
return 0;