In my C application, I want to calculate sunrise/sunset times for a given date, latitude and longitude. i have been searching on the net but i can not find a working sample.
But this sample didnt work correctly.
Is there a simple C source code or method which i can easly implement in my application?
Edit:
I implement the code on this link but it gave me the wrong sunset/sunrise values. Also i tried the Saul's link here but it gave me the wrong result either.
I have 41N, 28E location. When i try the codes, both sample says that sunrise value is aproximately 10:13 and sunset is 23:24. But the correct values are 06:06, 20:13.
I can not understand the problem.
解决方案
The sample code appears to work in VC++ 2010 with a few minor changes:
Compile it as a C++ file and not C.
Remove the #include line.
Add a #define _USE_MATH_DEFINES at the top of the file in order for M_PI to be defined.
Change the two %T in the strftime() calls to %X.
Now that you have a working sample you can debug the working version and your version to see where the calculation begins to differ and narrow in on the issue. Either step through the program or make liberal use of temporary printf() calls much like the sample does.
If you want specific help you will have to post your code (either a link to the entire file or particular snippets you need help with).