在以下代码之后添加一些套接字连接代码后,我遇到了这个问题。什么时候可以fp
,指向一些内存地址,同时读取数据(第 4 行),但是当调试器(gdb)到达if
块时,fp
指针只是指向 0x0。
#define CHANNELS_PER_IOM 25
...
int OldValues[CHANNELS_PER_IOM];
FILE * fp;
FILE * fp_t;
int buff;
int i;
fp = fopen("/windcom/tmp/dout_values", "r");
fp_t = fopen("/windcom/tmp/dout_values.tmp", "w");
i = 0;
while(fp && fscanf(fp, "%d\n", &buff) == 1) // fp is pointing some address here.
{
i++;
OldValues[i-1] = buff;
//printf("%d %d \n", OldValues[i-1], buff);
}
if(!fp) //fp is pointing 0x0 here.
{
for(i=0; i<CHANNELS_PER_IOM; i++)
{
OldValues[i] = 0;
}
}