Date and Time

This is a discussion on Date and Time within the C Programming forums, part of the General Programming Boards category; I have a function that returns a date and hour with a specified format. Code: int c = 0; char ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    29

    Date and Time

    I have a function that returns a date and hour with a specified format.

    Code:
    int c = 0;
    char stringdate[] = {'\0'};
    
    int date(void) {
      
      time_t now;
      struct tm *tm_now;
      char buff[BUFSIZ];
      
      now = time(NULL);
      tm_now = localtime(&now);
    
      strftime(buff, sizeof buff, "%d-%m-%Y:%H:%M:%S", tm_now);
      printf("%s", buff);
      // stringdate[c++] = buff;
      return 0;
    }
    My program does a scanf of various characters and then in the end of the program it retrieves the date and time of each character inputted.
    But i can only retrieve the date and time of the last inputted character.
    How can i do this?

    Thanks

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    char stringdate[] = {'\0'};
    You do know that this array is only big enough to hold a single character, right?

    Other than that you'll have to clarify your question.
    But i can only retrieve the date and time of the last inputted character.
    How can i do this?
    How can you do what?

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    29
    Retrieve the date of all inputted characters.

    Example: a
    26-11-2004:11:50:10 // WIll not appear, it only appears at the end
    of the program
    b
    26-11-2004:11:50:20 // " "

    g
    26-11-2004:11:51:02 // " "

    My program just retrieve the last date: 26-11-2004:11:51:02

    I want that it retrieves the 3 datas.

    Output: 26-11-2004:11:50:10
    26-11-2004:11:50:20
    26-11-2004:11:51:02

  4. #4
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    How about when you receive input via a function, soon as you get the character, input, etc, then you use date() or use some other os specific function for more specific times.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advancing day by day until it matches a second date
    By nhubred in forum C++ Programming
    Replies: 1
    Last Post: 05-30-2009, 09:55 AM
  2. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 04:25 PM
  3. How to get and set windows time and date
    By huwan in forum Windows Programming
    Replies: 18
    Last Post: 05-13-2008, 11:33 AM
  4. Sending an email in C program
    By Moony in forum C Programming
    Replies: 28
    Last Post: 10-19-2006, 11:42 AM

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