# define FOUND 1
# define NOTFOUND 0
int k,flag,a;
char cmp_string[10]; //used to get one array element to compare with all other array elements
char *values[]={010,020,030,040}; //valid case that's how it should be
char *vales[]={010,020,020,030}; wrong or throw error because in array i should have only unique values
int size=4;
for(k=0; k<=size;k++){
strcpy(values[k],cmp_string);
flag=NOTFOUND;
int counter=k+1;
for(int n=counter;n<=size;n++)
{
a=((strcmp(values[n],cmp_string) || (strcmp(values[k-1],cmp_string)))
// stuck here what if k value is 2 I wont be able to compare with zero or first element of array.
if(a==0){
throw error same name for the operation
flag=FOUND;
break;
}
}//for int n;
}//for int k;
if(flag==NOTFOUND){
True or PASS
}
}
答案 0 :(得分:2)
快速解决方案:对数组进行排序(使用例如内置qsort
函数),然后扫描它比较相邻元素;如果两个是相同的,你就会重复。
如果在比较函数中您发现两个比较项目相同,您也可以在完成排序之前知道您有重复项。
答案 1 :(得分:0)
如果我正确理解了您的问题,那么您尝试将strcmp
变为非零,如果字符串相同则返回非零值,否则为零:
a = (strcmp(whatever) != 0) || (strcmp(whatever else) != 0);