I am trying to write counter output to a file when ir sensor detects
obstacle..
So, when i run the code and try to place object in front of the sensor, sometimes it hangs.. so i tried 100 iteration to write to file and noticed it do stuck at least 2 to 3 times in every 100 iteration..
Any idea hw to solve or better method ?
Code: Select all
void detected(int count)
{
fp = fopen("raw", "w");
char buffer[6] ;
snprintf(buffer, sizeof(buffer), "%d",count);
size_t len = 0;
len=strlen(buffer);
fwrite(buffer, len, 1, fp);
fclose(fp);
}
void test()
{
for (int i=0;i<100;i++)
{
detected (i);
}
}