title: How to compare two structs in c?
body: <p>I know, that if i want to compare two structs than i have to write it for myself, because there isn't any function for this, but i can't figure out how should i do that. I have three structs : primary, secondarystruct, and difference(this should contain the different items). All three has the following members : char * filename, char * size, int size.</p>
  
  <p>All i need are those items which aren't in the secondarystruct , or if they are then i need them only if their size is bigger then the secondarystruct's size. Hope you understand what i want. My english isn't the best, sorry for this.</p>
  
  <p>Here is what i tried:</p>
  
  <pre><code>j = 0;
  x = 0;
  for ( i = 0; i &lt; primarypcs; )
  {
      memset( tmp, 0, sizeof( tmp ) );
      l = 1;
      for ( k = 0; k &lt; strlen( primary[i].filename );k++ )
      {
          tmp[k] = primary[i].filename[l];
          l++;
      }
      tmp[k]='\0';
  
      memset( buf, 0, sizeof( buf ) );
      l = 1;
      for ( k = 0; k &lt; strlen( secondarystruct[j].filename ); k++ ) //&lt;-- here is where my program freezes
      {
          buf[k] = secondarystruct[j].filename[l];
          l++;
      }
      buf[k]='\0';
  
      if ( ( stricmp( tmp, buf ) == 0 ) &amp;&amp; ( x == 0 ) )
      {
          if ( primary[i].intsize &gt; secondarystruct[j].intsize )
          {
              difference[diff].filename = strdup( primary[i].filename );
              difference[diff].size = strdup( primary[i].size );
              difference[diff].intsize = -1;
              diff++;
              i++;
              if ( j == secondarypcs ) x = 1;
              else j++;
          }
          else if ( x == 0 )
          {
              i++;
              if ( j == secondarypcs ) x = 1;
              else j++;
          }
      }
      else
      {
          difference[diff].filename = strdup( primary[i].filename );
          difference[diff].size = strdup( primary[i].size );
          difference[diff].intsize = -1;
          diff++;
          i++;
      }
  }
  </code></pre>
  
  <p>Please tell me what i'm doing wrong! </p>
  
  <p>Thanks, kampi</p>
  
  <p>Update:</p>
  
  <p>Sorry, it seems, i gave you not enough information.
  So: both structures are containing file list, from different drives, like "C:\" and "D:\". This is the reason why i can't use just simple strcmp, because the first letter will always differ. That's why i have to "cut them off" and then compare. This program should work like this: It retrieves the file list from c:\ and then retrieves the filelist from d:\ and then compares them. If on file which is on c:\ doesn't exists on d:\ then it should be copied there, if on d:\ there is a file which doesn't exists on c:\ then it should be ignored(i don't wan't to do with it anything). If a file which is found in c:\ and d:\ as well, then i wan't to copy it only then if the file from c:\ has a bigger size than a file which is on d:\</p>
  
  <p>Hope you understand now what i want.</p>