String Compare Using Dynamic Arrays

This is a discussion on String Compare Using Dynamic Arrays within the C Programming forums, part of the General Programming Boards category; what i want to do is to compare the current read in string 'street_name' which has a single name then ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    32

    Unhappy String Compare Using Dynamic Arrays

    what i want to do is to compare the current read in string 'street_name' which has a single name then compares then reads a new name. And a previously read in string array in 'comp_street_name' which has 20 names in a string array.all strings are read in and working fine.

    i want it to compare 'street_name' to the 1st 'comp_street_name' and keep going through comparing until the end of the 'comp_street_name' array.

    both strings are dynamic ones. check the declaration below. the 1st string is in a struct with a pointer. the 2nd string is just a global array. 'st_name' in the for loop is just a counter of how many 'comp_street_name's there are. 'a' is passed in from the read function and is just where the read in string is.

    DECLARATION:
    Code:
    char street_name[MAX][STR_MAX];
    char comp_street_name[MAX][STR_MAX];
    PART OF FUNCTION:
    Code:
    for(b = 0; b < st_name; b++)
    {
       if(strcmp(fptr->street_name[a][b], comp_street_name[a][b]) == 0) /* Compare strings to find a valid address */
       {
          check++;                                    /* Add one to checker for correct address part */
       }
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    for( x = 0; x < snmax; x++ )
        for( y = 0; y < csnmax; y++ )
            if( strcmp( street_name[ x ], comp_street_name[ y ] ) == 0 )
                ...this one matches...
    Like that?

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    32
    yes, it seems i must make my own string compare to do this. as it would be just 'to simple' to just call one built in function.

    thanx once again quzah.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Ok, so write your own version of strcmp, and call it instead of the stock one. Your code will look much cleaner in doing so, than it will if you add more layers of looping by visibly walking through each array. Let a function do that for you.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Posts
    32
    ok thanx for the help quzah

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 05:30 PM
  2. string arrays
    By Molokai in forum C++ Programming
    Replies: 2
    Last Post: 11-04-2007, 12:21 AM
  3. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  4. string arrays
    By Raison in forum C Programming
    Replies: 27
    Last Post: 10-02-2003, 07:27 PM
  5. string handling
    By lessrain in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 08:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21