Urgent help please

This is a discussion on Urgent help please within the C Programming forums, part of the General Programming Boards category; OK I have a program due in tomorrow and I need to calculate the number of days that have passed ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    2

    Exclamation Urgent help please

    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??

    Please help as soon as possible, it will be greatly appreciated.

  2. #2
    Registered User
    Join Date
    Aug 2006
    Posts
    99
    1) Get Calender.
    2) Find Today.
    3) Count Backwards.
    4) ???
    5) Profit!

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    2
    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. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,720
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    Well then, do you have any working code or logic for this? If not, then get started with the logic.
    Otherwise, post your current attempt and ask specific questions about what you don't understand.
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by watsee View Post
    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!
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    ...Uh, right.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Quote Originally Posted by laserlight View Post
    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...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  9. #9
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Quote Originally Posted by MK27 View Post
    Forty!
    Dang it! I thought the answer was *always* 42!!!!!
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  10. #10
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    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.

    Quote Originally Posted by jeffcobb View Post
    Dang it! I thought the answer was *always* 42!!!!!
    Only on Thursday.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,720
    Quote 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
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #12
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Programmers can be such smart@sses

    Its why I love this gig...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  13. #13
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Quote Originally Posted by laserlight View Post
    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...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  14. #14
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,720
    At a glance, 'thursday' should be "thursday".
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  15. #15
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Quote Originally Posted by laserlight View Post
    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()
    
    // instead of 
    <someobject>.foo();
    Last edited by jeffcobb; 02-09-2010 at 11:47 AM.
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Urgent Help Needed In Writing Algorithm!!
    By Vikramnb in forum C++ Programming
    Replies: 1
    Last Post: 01-09-2009, 11:46 AM
  2. BitWise Newbie - Needs Urgent Help
    By frodonet in forum C Programming
    Replies: 15
    Last Post: 09-26-2007, 12:58 PM
  3. display character size...(quite urgent..)
    By karthi in forum C Programming
    Replies: 10
    Last Post: 07-11-2007, 09:42 PM
  4. beginner plzz help urgent
    By sara101 in forum C Programming
    Replies: 11
    Last Post: 01-14-2007, 09:38 PM
  5. printing the output its urgent
    By yviswanadham in forum C Programming
    Replies: 6
    Last Post: 12-26-2004, 09:27 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21