-
Strange problem
Hi,
Could anyone please explain this problem to me?
I use:
Code:
while(!feof(f))
{
fgets (all_id, 100 , f);
sscanf (all_id,"%*s %s %s",a_id,d_id);
str[i] = a_id;
printf("\n%s",str[i]);
strtok(a_id,"G");
ida = strtok (NULL, "G");
idsa[i]=atoi(ida);
i++;
}
printf("\n%s",str[2]);
Even if I use strncpy in place of strtok, the value retained by the str is the last value assigned to it using str[i]=a_id!
Why cannot the str retain its value outside loop?
I'll be obliged if anyone could explain this fundamental misconception of mine?
Thanks,
Angkar
-
Precisely I see its a stale value! When I switch back to strtok again, its throwing the value of the last result that I got using strncpy!!!
-
Try changing the loop to something other than feof. Why it's bad to use feof() to control a loop It can cause some wierd things about how many times the loop runs. Fix that, it might help.
~Sven
-
What are the alternatives?
-
> What are the alternatives?
Sticking to one thread and not spamming the board would help.