Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

String Comparisons, EXACT...

SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
OK, I need to compare two string's text, even if the strings are not the same length. An example may clear up what I am trying to do.
[code]
char str1[32] = "Meow";
char str2[8] = "Meow";
char str3[16] = "Meowing";
[/code]
Now, regardless of the different sizes, how can I test just the text that is in them, for an EXACT match? From the above sources, if I compared 1 and 2 I want it to be TRUE, and if I compared 1 and 3 or 2 and 3, I'd want it to be FALSE. Is there a C/C++ function that can do this? I have tried things with "strstr" and "strcmp/strcmpi", but none do it properly and the results are invalid settings for my combo boxes. I have even had a combo box set itself to a setting that isn't anywhere in the string, and I can NOT figure out why because there isn't anything remotly close to what is required to set the answer it gave me. Any ideas?

-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

Comments

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : OK, I need to compare two string's text, even if the strings are not the same length. An example may clear up what I am trying to do.
    : [code]
    : char str1[32] = "Meow";
    : char str2[8] = "Meow";
    : char str3[16] = "Meowing";
    : [/code]
    : Now, regardless of the different sizes, how can I test just the text that is in them, for an EXACT match? From the above sources, if I compared 1 and 2 I want it to be TRUE, and if I compared 1 and 3 or 2 and 3, I'd want it to be FALSE. Is there a C/C++ function that can do this? I have tried things with "strstr" and "strcmp/strcmpi", but none do it properly and the results are invalid settings for my combo boxes. I have even had a combo box set itself to a setting that isn't anywhere in the string, and I can NOT figure out why because there isn't anything remotly close to what is required to set the answer it gave me. Any ideas?
    :
    : -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
    :
    [blue][b]strcmp()[/b] works perfectly. Can you post some code - how you were using it?[/blue]
  • SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
    [code]
    void PaintWindows(HWND pwnd)
    {
    unsigned char ILoop;

    ILoop = 0;
    for(short int WLoop = IDC_ITEM_A; WLoop <= IDC_ITEM_J; WLoop++)
    {
    if(strstr(Items[ILoop], "FSVEN") != NULL)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 0, 0);
    if(strstr(Items[ILoop], "M92F") != NULL)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 1, 0);
    if(strstr(Items[ILoop], "DE50") != NULL)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 2, 0);
    if(strstr(Items[ILoop], "M3") != NULL)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 3, 0);
    if(strstr(Items[ILoop], "MP5") != NULL)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 4, 0);
    if(strstr(Items[ILoop], "PSG") != NULL)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 5, 0);
    if(strstr(Items[ILoop], "P90") != NULL)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 6, 0);

    if(strstr(Items[ILoop], "*FSVEN") != NULL)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 11, 0);
    if(strstr(Items[ILoop], "*M92F") != NULL)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 12, 0);
    if(strstr(Items[ILoop], "*DE50") != NULL)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 13, 0);
    if(strstr(Items[ILoop], "*M3") != NULL)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 14, 0);
    if(strstr(Items[ILoop], "*MP5") != NULL)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 15, 0);
    if(strstr(Items[ILoop], "*P90") != NULL)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 17, 0);
    if(strstr(Items[ILoop], "*P90") != NULL)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 17, 0);


    if(strstr(Items[ILoop], "#M3FLSH") != NULL)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 24, 0);
    if(strstr(Items[ILoop], "#MP5AIM") != NULL)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 25, 0);
    if(strstr(Items[ILoop], "#MP5SIL") != NULL)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 26, 0);
    if(strstr(Items[ILoop], "#P90AIM") != NULL)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 28, 0);
    if(strstr(Items[ILoop], "#P90FLSH") != NULL)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 29, 0);

    ILoop++;
    }

    return;
    }
    [/code]
    The # symbol denotes an attachment, such as a flashlight or suppressor. An asterik denots a clip of ammo. Anyways, "Items" is a 16x16 array of chars. Any errors here?

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

  • SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
    Figured I'd better paste the function that adds strings to the combo boxes as well. Here is the whole source for adding items to the boxes and then the source for setting them based on what is in my Items array. And I have made a debug dialog box that shows me what the Items array holds. It holds these strings: Items[0] is "M3", Items[1] is "#M3FLSH", Items[2] is "*M3", and the rest are correct as well. However, the painting routine somehow selects H&K MP5 twice, then a blank box, then RC50 Ammo! What the HECK is going on?
    [code]
    void PaintWindows(HWND pwnd)
    {
    unsigned char ILoop;

    ILoop = 0;
    for(short int WLoop = IDC_ITEM_A; WLoop <= IDC_ITEM_J; WLoop++)
    {
    if(strcmp(Items[ILoop], "FSVEN") == 0)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 1, 0);
    if(strcmp(Items[ILoop], "M92F") == 0)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 2, 0);
    if(strcmp(Items[ILoop], "DE50") == 0)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 3, 0);
    if(strcmp(Items[ILoop], "M3") == 0)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 4, 0);
    if(strcmp(Items[ILoop], "MP5") == 0)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 5, 0);
    if(strcmp(Items[ILoop], "PSG") == 0)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 6, 0);
    if(strcmp(Items[ILoop], "P90") == 0)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 7, 0);

    if(strcmp(Items[ILoop], "*FSVEN") == 0)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 13, 0);
    if(strcmp(Items[ILoop], "*M92F") == 0)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 14, 0);
    if(strcmp(Items[ILoop], "*DE50") == 0)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 15, 0);
    if(strcmp(Items[ILoop], "*M3") == 0)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 16, 0);
    if(strcmp(Items[ILoop], "*MP5") == 0)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 17, 0);
    if(strcmp(Items[ILoop], "*PSG") == 0)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 18, 0);
    if(strcmp(Items[ILoop], "*P90") == 0)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 19, 0);


    if(strcmp(Items[ILoop], "#M3FLSH") == 0)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 26, 0);
    if(strcmp(Items[ILoop], "#MP5AIM") == 0)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 27, 0);
    if(strcmp(Items[ILoop], "#MP5SIL") == 0)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 28, 0);
    if(strcmp(Items[ILoop], "#P90AIM") == 0)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 30, 0);
    if(strcmp(Items[ILoop], "#P90FLSH") == 0)
    SendMessage(GetDlgItem(pwnd, WLoop), CB_SETCURSEL, 31, 0);

    ILoop++;
    }

    return;
    }

    void SetupLists(HWND bwnd)
    {
    char ListBuffer[4];

    for(int Loop = IDC_ITEM_A; Loop <= IDC_ITEM_J; Loop++)
    {
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 1, (LPARAM)"Five Seven");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 2, (LPARAM)"Beretta M9");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 3, (LPARAM)"Desert Eagle");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 4, (LPARAM)"Benelli M3");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 5, (LPARAM)"H&K MP5");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 6, (LPARAM)"H&K PSG1");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 7, (LPARAM)"P90");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 8, (LPARAM)"AKMSU");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 9, (LPARAM)"M16 Colt Rifle");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 10, (LPARAM)"Giat FA MAS G2");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 11, (LPARAM)"SG 551-SWAT");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 12, (LPARAM)"Robar RC50");

    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 13, (LPARAM)"Five Seven Ammo");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 14, (LPARAM)"Beretta Ammo");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 15, (LPARAM)"DE Ammo");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 16, (LPARAM)"M3 Ammo");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 17, (LPARAM)"MP5 Ammo");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 18, (LPARAM)"PSG1 Ammo");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 19, (LPARAM)"P90 Ammo");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 20, (LPARAM)"AKMSU Clip");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 21, (LPARAM)"AKMSU Drum");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 22, (LPARAM)"M16 Ammo");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 23, (LPARAM)"FA MAS G2 Ammo");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 24, (LPARAM)"SG 551 Ammo");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 25, (LPARAM)"RC50 Ammo");

    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 26, (LPARAM)"M3 Flashlight");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 27, (LPARAM)"MP5 Scope");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 28, (LPARAM)"MP5 Suppressor");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 29, (LPARAM)"PSG1 Scope");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 30, (LPARAM)"P90 Scope");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 31, (LPARAM)"P90 Suppressor");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 32, (LPARAM)"M16 Scope");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 33, (LPARAM)"M203 Launcher");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 34, (LPARAM)"SG 551 Laser");
    SendMessage(GetDlgItem(bwnd, Loop), CB_ADDSTRING, 35, (LPARAM)"SG 551 Scope");
    }

    for(unsigned char Loop = 0; Loop < 32; Loop++)
    {
    sprintf(ListBuffer, "%i", Loop);
    SendMessage(GetDlgItem(bwnd, IDC_LOADNUM), CB_ADDSTRING, Loop, (LPARAM)ListBuffer);
    }

    return;
    }
    [/code]
    Thanks for your time ASM.

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

  • SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
    Figured two things out that fixed the problem. First, I was starting at 1 instead of 0 in the listboxes, and that setting the WPARAM when adding text does nothing. The next was that, for some reason, Infiltration stores the MP5 weapon and ammo as MP540, yet everything else for it is just MP5. Made the changes and it runs perfectly. Now I just have to make a function that will put your selections into Inf format, then write it to the file. Thanks anyways guys :P.

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    [blue]Are you trying to kill your P-IV or what?!.. (j/k)

    Seriously, you used a pile of code to do a simple thing. As I get it - you connected the text string of a combo box list to some ID (1,2,3...) and then you selecting it based on the text again.

    You should have written a routine to find the item by its text ([b]CB_FINDEXACTSTRING[/b]) and then select it as usual.

    Also, why 32 times [b]GetDlgItem()[/b]? Use some locals, man...

    HWND hCombo = GetDlgItem(...);

    SendMessage (hCombo, ...);
    SendMessage (hCombo, ...);
    // ...
    SendMessage (hCombo, ...);

    Also, you should have used the array to store your items:[code]
    static CHAR* arr [] = {
    "Weapon #1",
    "Weapon #2",
    "Ammo #1",
    "Ammo #2", ..etc
    };
    [/code]...and then just scanned it with [b]for()[/b] to add items to a combo box.
    [/blue]
  • SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
    Well it works kind of the opposite from that. The array changes with each config loaded (Infiltration supports 32 configs) so I put every weapon and item in the dialog boxes. Now when a config is loaded, the boxes are set to show what is in the config. The user may then change, remove, or add items to the config by altering the ten combo boxes. He/She may then save the config as it was, or as a new one. I'll send it to you when I finish it, although you may not find it useful unless you play Infiltration for UT :P!

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

  • Chris BrownChris Brown USAMember Posts: 4,496 ✭✭

    _______ < http://forcoder.org /> free ebooks and video tutorials about \ Visual Basic, C, MATLAB, Ruby, Objective-C, Go, Scratch, PL/SQL, Java, Swift, Assembly, Delphi, C++, JavaScript, Visual Basic .NET, C#, Perl, PHP, Python, R ML, LabVIEW, Apex, Julia, Prolog, Scheme, Kotlin, Lisp, Hack, Rust, D, Scala, Awk, Erlang, ABAP, VBScript, Alice, Logo, Lua, Fortran, Ada, COBOL, Clojure, F#, Transact-SQL, Dart, FoxPro, SAS, Bash, Crystal \ ___

Sign In or Register to comment.