我的循环内的函数以某种方式改变了我正在迭代的值,但我不确定如何改变。如果描述得很糟糕,我很抱歉。
在这个 for 循环内
int k;
for( k = 0; k < 512; k++)
{
// Discardheader(d); // doesnt actually do anything, since it's a header.f
int databit = Getexpecteddata(d+4*k+1);
printf("%d ",k);
int transmitted = Datasample(&datastate, &datalength, d+4*k+2,dataerr,dataloc, databit);
printf("%d ",k);
Clocksample(&clockstate, &clocklength, d+4*k+3,clockerr, transmitted);
printf("%d \n",k);
}
我得到这个输出
16 16 16
17 17 17
18 18 18
19 19 19
20 20 20
21 1 1
2 2 2
3 3 3
4 4 4
因此,Datasample 在达到 21 时就会更改 k 的值。d 是 char * d 类型,表示我在其中读取文件的缓冲区。更改输入文件不会改变 21 处发生的切换。这是数据样本的代码:
int Datasample (int* state, int* length, char *d, int *type, int location, int data)
{
int match = 1; // if data sample and delayed tx match,
if ( ((d[0] >> location) & 1) != data)
{
match = 0;
if(data)
{
type[2]++;
}
else
{
type[1]++;
}
}
int ia;
for( ia = 7; ia>=0; ia--)
{
if ( ((d[0] >> ia) & 1) == *state) // finds an edge
{
*length++;
}
else
{
int distance, deviation,devflag=1; // distance the edge is from the sample point. should be about 4
if ( location > 3) // deviation is how far the distance then is from 4
{distance = location - ia;}
else
{distance = ia - location;}
deviation = abs(4-distance);
if( (deviation >= devmax) && match && devflag)
{
devflag =0;
if(data)
{
type[2]++;
}
else
{
type[1]++;
}
}
*state = ((d[0] >> ia) & 1);
*length = 1;
}
}
return ((d[0] >> location) & 1);
}
是什么导致 k 一旦达到 21 就回滚到 1?
提前致谢。我不知道我在做什么。