Improving SD card logger script

I see a sketch that writes data every time through loop.

I have a project that writes data about 1000 times a day. It goes for weeks without any hiccups. Makes me wonder what's up with yours.

Although I'm not sure it would matter I'd declare tempc as a float instead of int.

Also

for(int i = 0; i < 8; i++) {tempc += analogRead(pin);}

might be problematic as you aren't clearing tempc first. It's probably not stopping your sketch but may be effecting your results. Put a tempc = 0 statement right before the if.

I do use a different library for my 1307 clock though and I wonder if your problem is there. I use the Time.h lib from the Arduino site. It has a lib for the 1307 included. I had no problems with it. I even get very accurate time. It's drifted a few seconds over a few months.

http://www.arduino.cc/playground/Code/time