OK I have a program due in tomorrow and I need to calculate the number of days that have passed since the first day of the year. Can anyone PLEASE help me with the code for this??

2. 1) Get Calender.
2) Find Today.
3) Count Backwards.
4) ???
5) Profit!

3. OK I half expected a reply like that, come on man please. Its not even for me its for my girlfriend, maaaaajor brownie points if I get this working for her. So come on please someone out there must be able to help me properly.

4. That makes it even worse, methinks

Anyway, one idea is to compute the number of days that have gone by in the previous months of the year, and then add the number of days that have gone by in the current month.

5. Well then, do you have any working code or logic for this? If not, then get started with the logic.
Furthermore, I would refrain from using "urgent" and "help" in the title. Members will reply at their own pace, when and if they can, regardless if you put in urgent or not. And help isn't very specific.
Such titles ever deter some members.

6. Originally Posted by watsee
OK I have a program due in tomorrow and I need to calculate the number of days that have passed since the first day of the year. Can anyone PLEASE help me
Forty!

7. ...Uh, right.

8. Originally Posted by laserlight
That makes it even worse, methinks

Anyway, one idea is to compute the number of days that have gone by in the previous months of the year, and then add the number of days that have gone by in the current month.
Maybe the long way around the block but could conceivably result in shorter code is to get a Gregorian to Julian date converter fn from snippets.org, then call it twice, once with current date and once with 01012010 and subtract...

9. Originally Posted by MK27
Forty!
Dang it! I thought the answer was *always* 42!!!!!

10. I'd figure out the "seconds since the epoch" for 1/1/10 and then use difftime(). There are 3600 seconds in a day.

For further help I think the OP needs to include a pic of the girlfriend.

Originally Posted by jeffcobb
Dang it! I thought the answer was *always* 42!!!!!
Only on Thursday.

11. Originally Posted by MK27
Only on Thursday.
If the girlfriend submits the homework tomorrow (today?), it will probably get marked on Thursday, which is just right

12. Programmers can be such smart@sses

Its why I love this gig...

13. Originally Posted by laserlight
If the girlfriend submits the homework tomorrow (today?), it will probably get marked on Thursday, which is just right
Note one line of code yet either. Lemme fix that.

So if he/she turned it in on Thursday:
Code:
```#include <stdio.h>
#include <string.h>

int main(int argc, char*argv[])
{
int nRC = 0;
char today[20];
memset(today, 0, 20);
// get the command line of day
if(argc > 1)
{
strncpy(today, argv[1], 20);
}

if( strcmp(today, 'thursday')==0)
{
printf("42!\n");
}
else
{
printf("Error in computation or input. Try again.\n");
// tell calling system that we are MASSIVE FAIL
nRC = -1;
}
return nRC;
}```
There. That way if the app is called like so:
./myapp thursday
the correct answer will indeed pop out...

14. At a glance, 'thursday' should be "thursday".

15. Originally Posted by laserlight
At a glance, 'thursday' should be "thursday".
Sorry was just doing some Python....my mistake!

You know, all joking aside, that can be one of the tricky things about constantly living with multiple languages with similar but not exact syntactical styles....and the single/double quote problem is only one. Like going from Object PASCAL to C++ I get wanting to do things like:

Code:
```with <someobject> do:
foo()