I know that if I want to compare two structures, then I have to write this for myself, because there is no function for this, but I cannot figure out how to do this. I have three structures: primary, secondary structure and difference (this should contain different elements). All three have the following members: char * filename, char * size, int size.
All I need are those elements that are not in the secondary structure, or if I need them then, only if their size is larger than the size of the secondary structure. I hope you understand what I want. My English is not the best, sorry for that.
Here is what I tried:
j = 0; x = 0; for ( i = 0; i < primarypcs; ) { memset( tmp, 0, sizeof( tmp ) ); l = 1; for ( k = 0; k < 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 < strlen( secondarystruct[j].filename ); k++ ) //<-- here is where my program freezes { buf[k] = secondarystruct[j].filename[l]; l++; } buf[k]='\0'; if ( ( stricmp( tmp, buf ) == 0 ) && ( x == 0 ) ) { if ( primary[i].intsize > 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++; } }
Please tell me what I'm doing wrong!
Thanks kampi
Update:
Sorry, I seem to have given you not enough information. So: both structures contain a list of files from different drives, such as "C: \" and "D: \". It is for this reason that I cannot use just plain strcmp, because the first letter will always be different. That is why I have to "disable them" and then compare. This program should work as follows: it extracts a list of files from c: \, and then extracts a list of files from d: \, and then compares them. If the file that is on c: \ does not exist on d: \, then it should be copied there, if on d: \ there is a file that does not exist on c: \, then it should be ignored (I should not do nothing about it). If the file that is in c: \ and d: \, then I will not copy it only if the file from c: \ is larger than the file that is in d: \
I hope you now understand what I want.
source share