char * getHint(char * secret, char * guess){ if (secret == NULL || guess == NULL) { return "0A0B"; } int len, i, bulls=0, cows=0; int nums1[10]={0}, nums2[10]={0}; char *res; res = calloc(sizeof(char) * 1000, 1); len = strlen(secret); for (i=0; i<len; ++i) { if (secret[i] == guess[i]) {++bulls;} else { nums1[secret[i]]++; nums2[guess[i]]++; } } for (i=0; i<10; ++i) { cows += ((nums1[i] < nums2[i]) ? nums1[i]:nums2[i]); } sprintf(res, "%dA%dB", bulls, cows); return res; }