Comparing 2 elements from 2 different arrays

This is a discussion on Comparing 2 elements from 2 different arrays within the C Programming forums, part of the General Programming Boards category; I have two arrays that I'm trying to compare to see if the values are the same and then use ...

  1. #1
    System-7
    Join Date
    Nov 2005
    Posts
    65

    Comparing 2 elements from 2 different arrays

    I have two arrays that I'm trying to compare to see if the values are the same and then use it in an if statement to compare. Here they are declared:
    Code:
    static char *my_argv[100];
    
    strcpy(execCommands->command[0],"blank");  
    //The 2nd one is from a structure i have tested it and it has the correct value
    //The way I tested both of them is below
    printf("ARGV: %s / COMMAND: %s", my_argv[0], execCommands->command[0]);
    And this is what I tried to use to compare them:
    Code:
    if (strcmp(my_argv[0], execCommands->command[0]))
         printf("FOUND BLANK");
    Thanks for any help you can give,

    Dan

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Since you neglected to tell us what the problem is, I'll guess. You want this:
    Code:
    if (strcmp(my_argv[0], execCommands->command[0]) == 0)
    My best code is written with the delete key.

  3. #3
    System-7
    Join Date
    Nov 2005
    Posts
    65
    Oh sorry, the problem is that it seems to think that they are not equal when i input the value 'blank' so that it should enter the if statement

    I just tried that and it works. Thanks for the quick reply ....something so small lol

    Dan

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Woohoo! I get a cookie for being right!

    /me dances
    :D\-<
    :D|-<
    :D/-<
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to Compare elements in arrays
    By axe in forum C Programming
    Replies: 13
    Last Post: 11-16-2007, 03:04 AM
  2. Comparing elements of character pointer arrays
    By axe in forum C Programming
    Replies: 2
    Last Post: 11-14-2007, 12:20 AM
  3. Replies: 7
    Last Post: 04-13-2003, 11:53 PM
  4. ? comparing elements of a char array
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 09-20-2001, 08:55 AM
  5. elements of arrays; functions
    By sballew in forum C Programming
    Replies: 6
    Last Post: 09-03-2001, 02:48 AM

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