Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Will answer your previous post after I get home. Seems an earlier attempt post didn't make it. I added a delay to the code; the code no longer failed.

for (i =0; i < 1000000; i++);

after popen, fgets (not sure)

Accuracy is important. So post the exact code when you can do so, rather than guess at it when unsure. And in general, posting complete code is better than posting code fragments that have to be manually edited or combined to produce a whole.

And in addition to my earlier question about OS version and gcc version, please identify the CPU architecture by choosing "About This Mac" from the Apple menu, and posting the exact value listed after Processor.
 
Definitely a timing issue. Launching popen, starts a process on its own clock. It needs to be synced with the launching code.

Thanks.
 
Definitely a timing issue. Launching popen, starts a process on its own clock. It needs to be synced with the launching code.
Excessive brevity hinders intelligibility. Expand?


If you need a real-time delay, don't use an empty loop. For one thing, the optimizer could remove it.

To delay for a fixed time, see the usleep() C function. Read its man page:
Code:
man usleep
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.