#include <stdio.h>
void check(char *nums_input, int *nums, int *num_accord);
int main(int argc, char *argv[])
{
int nums[4]={0, 1, 2, 3};
char *nums_input = "0124";
int num_accord=0;
do {
check(nums_input, nums, &num_accord);
printf("%d\n", num_accord);
} while (num_accord!=4);
return 0;
}
void check(char *nums_input, int *nums, int *num_accord)
{
int i;
int j;
for (i=0;i<4;i++) {
for (j=0;j<4;j++) {
if (nums_input[i] == '0'+nums[j]) {
*num_accord++;
break;
}
}
}
}
大概是这样的
定义int型数组{0, 1, 2, 3}
还有字符串"0124"
想逐一比较字符串里的数字字符和int型数组里的元素是否相同,相同时,定义的num_accord加1
我写的函数void check(char *nums_input, int *nums, int *num_accord)正是为了实现逐一比对的需求
我明明传入的是num_accord的指针,为什么在check函数内部执行*num_accord++,没能够实时更改外部的num_accord的值