Search code examples
ctelecommunication

1D string Array comparison with 2D string Array in C


I am working on mobile communication Simulator based on C language. I have two different IPs which are stored as Strings in different format.

  1. For User it is XYZ[20]
  2. For Access Gateway, it is ABC[No. of Users][20]

Now, I need to compare both for one algorithm. but I am confused that how should I do them as both are different arrays. Is there any way to compare both 1D with 2D array ?


Solution

  • #include <string.h>
    ...
    for ( int i = 0; i < num_users; i++ )
    {
      if ( strcmp( ABC[i], XYZ ) == 0 )
      {
        // strings are equal
      }
      else
      {
        // strings are not equal
      }
    }
    

    ABC[i] is the i'th string stored in ABC.