Hey guys
I am looking and a piece of code that is masking and finding duplicates and I am trying to figure out what one piece of code does. The piece I don't understand is rc=match<=same.
Does anyone know what this does exactly and why it is relevant. I have never seen an assignment like this.
Code:#include <stdio.h> #define SIZE 5 int changeKey(int oldKey[], int newKey[], int n, int same) { int i, j, rc, match; match = 0; for (i = 0; i < n; i++) for (j = 0; j < n; j++) if (oldKey[i] == newKey[j]) match++; rc = match <= same; /*what exactly does this do*/ printf("RC IS %d\n",rc); printf("MATCH IS %d\n",match); if (rc == 1) for (i = 0; i < n; i++) oldKey[i] = newKey[i]; return rc; } void display(int key[], int n) { int i; for (i = 0; i < n; i++) printf("%d", key[i]); printf("\n"); } int main(void) { int key[] = {1,0,2,6,7}, rc; int attempt1[] = {2,7,4,5,9}; int attempt2[] = {1,8,5,2,9}; display(key, SIZE); rc = changeKey(key, attempt1, SIZE, 1); if (rc == 1) printf("Changed to: "); else printf("Remains as: "); display(key, SIZE); rc = changeKey(key, attempt2, SIZE, 2); if (rc == 1) printf("Changed to: "); else printf("Remains as: "); display(key, SIZE); rc = changeKey(key, attempt1, SIZE, 3); if (rc == 1) printf("Changed to: "); else printf("Remains as: "); display(key, SIZE); return 0; }



LinkBack URL
About LinkBacks


