-
Comparing
Hi,
Im trying to compare a char entered in a text box with another char.
At the moment it works fine, if the whole of the data field in the text box matches the stored char. It works.
eg,
text box - 01212222567
stored char - 01212222567
A match is produced.
Ideally i would like the user to enter just a small number eg, 0121 and it would recognise that it matches part of 01212222567 for example.
How would i go about doing this? :confused:
Here is the code im using at the moment.
Code:
else if (cli==1)
{
int item_txt_cli = GetDlgItemText(u_hDlg, IDC_CLI, cCli, 20);
if (strcmp(utDtiLine[viLine].sANI, cCli) == 0)
{
sprintf(sEventMessage, " %-3.3d Drop call %s %s Cause %d", viLine, utDtiLine[viLine].sANI, utDtiLine[viLine].sDNI, viCause);
vLog(sEventMessage);
}
else
{
//do nothing
}
}
As you can see im using strcmp.
Thanks for anyhelp whatsoever,
-
Thanks,
ermm, maybe i should of explaned more.
The utDtiLine[viLine].sANI char (the char which i want to compare the data in the text box to) is changed extremely often, every second say. It only stores one whole number at a time eg, 01212222567 (or 11 chars!)
and there is know way of knowing what this number is going to be!
So, any ideas??!
:confused:
cheers,
-
Can no-one help here??! :(
please, cant be that hard! Can it?!
thanks
-
This checks wether SmallString is the same as FullString's beginning (ie: SS = "Hello" & FS = "Hello world!")
Code:
bool Compare(char* SmallString, char* FullString)
{
int i = 0;
bool Result = true;
while((SmallString[i] != '\0') && (FullString[i] != '\0') && (Result == true))
{
if(SmallString[i] != FullString[i]) Result = false;
i++;
}
return Result;
}
-
yes, thats pretty smart coding magos, but that only finds if SmallString is at the beginning of FullString. If this is a problem, use the strstr() function...
-
thanks guys,
yeah it would be a problem. ie, i would need it to match say "Worl" with "Hello World" not just the begining.
So how would this strstr function work exactly within my code?
Could you give me an example if you dont mind!??
cheers,:p
-
If this line "if (strcmp(utDtiLine[viLine].sANI, cCli) == 0)" compares your two strings for equality, this line "if (strstr(utDtiLine[viLine].sANI, cCli) != NULL) will compare if the first string is part of the second. Look up the strstr function in your helpfile to get more info.
-
You could also replace your if statement:
Code:
if (strcmp(utDtiLine[viLine].sANI, cCli) == 0)
with this:
Code:
if (strcmp(utDtiLine[viLine].sANI, cCli) > strlen(shorterOne) || strcmp(utDtiLine[viLine].sANI, cCli) == 0)
to test if the mismatching character is after the shorterOne (which i don't know which one is) or if they are both equal.