hi fellow programmers, a bit of help if you will.
I am writing a program to search and replace certain lines/strings in a memo/richedit. Here is the code:
void __fastcall TForm1::Button2Click(TObject *Sender)
{
int i;
int n=0;
int token = 0;
//this sets up some strings so i can do a quick search for the word
char keyword[2][17]={"ZSOLDADDR1Z", "ZSOLDADDR2Z"};
//this allows me to use key codes to use with the caseswitch
enum{ZSOLDADDR1Z, ZSOLDADDR2Z};
//this increments each line
for(n=0; n<RichEdit1->Lines->Count; n++)
{
//this sets up my string for searching
String string=RichEdit1->Lines->Strings[n]+" ~";
//obviously, the keyword has to strat with 'Z' to make things easy
if(string[1]=='Z')
{
//this is where i search each enum and compare it to the strings. It is also where i get my error.(at the if)
for(i=0; i<=2; i++)
if(strncmp(keyword, &string[n], strlen(keyword))==0)
token=i;
//does the good stuff once keyword is found
switch(token)
{
//this area incomplete, cant get here yet to worry about it
case ZSOLDADDR1Z: RichEdit1->Lines->Strings[n]=Edit2->Text ; break;
case ZSOLDADDR2Z: break;
default: break;
}
}
}
}
In the strncmp where its in the if statement, i have three items. the first two are the items to be compared and the third the lenght to compare. At that point keyword == the enum strings and &string[n] == the line that the pointer is at... considering it gets to ZSOLDADDR1Z, borland kicks me out and points to ThrowIfOutOfRange(idx); in dstring.h.
If you could give me a hint of a reason why this small function is not working, i would be much obliged.
if i need to clarify, please be specific. if i need to shove off, be nice
I am writing a program to search and replace certain lines/strings in a memo/richedit. Here is the code:
void __fastcall TForm1::Button2Click(TObject *Sender)
{
int i;
int n=0;
int token = 0;
//this sets up some strings so i can do a quick search for the word
char keyword[2][17]={"ZSOLDADDR1Z", "ZSOLDADDR2Z"};
//this allows me to use key codes to use with the caseswitch
enum{ZSOLDADDR1Z, ZSOLDADDR2Z};
//this increments each line
for(n=0; n<RichEdit1->Lines->Count; n++)
{
//this sets up my string for searching
String string=RichEdit1->Lines->Strings[n]+" ~";
//obviously, the keyword has to strat with 'Z' to make things easy
if(string[1]=='Z')
{
//this is where i search each enum and compare it to the strings. It is also where i get my error.(at the if)
for(i=0; i<=2; i++)
if(strncmp(keyword, &string[n], strlen(keyword))==0)
token=i;
//does the good stuff once keyword is found
switch(token)
{
//this area incomplete, cant get here yet to worry about it
case ZSOLDADDR1Z: RichEdit1->Lines->Strings[n]=Edit2->Text ; break;
case ZSOLDADDR2Z: break;
default: break;
}
}
}
}
In the strncmp where its in the if statement, i have three items. the first two are the items to be compared and the third the lenght to compare. At that point keyword == the enum strings and &string[n] == the line that the pointer is at... considering it gets to ZSOLDADDR1Z, borland kicks me out and points to ThrowIfOutOfRange(idx); in dstring.h.
If you could give me a hint of a reason why this small function is not working, i would be much obliged.
if i need to clarify, please be specific. if i need to shove off, be nice