News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

<time.h>

Started by flamingo, August 04, 2011, 06:20:56 PM

Previous topic - Next topic

flamingo


#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#const int  LONG_CADENA=128;

int main(void)
{
  time_t t1;
  struct tm *t2;
  char cadena[LONG_CADENA];
 
  /* 1) get current date ('time_t') */
  if ((t1 = time(NULL)) == (time_t) -1)
     return EXIT_FAILURE;
 
  /* 2)get current date ('struct tm *') */
  t2 = localtime(&t1);
 
  /* print date manually through printf */
  printf("%d/", t2->tm_year + 1900);
  printf("%02d/", t2->tm_mon + 1);
  printf("%02d\n", t2->tm_mday);
 
  /* prints date through strftime */
  strftime(cadena, LONG_CADENA, "%Y/%m/%d", t2);
  printf("%s\n", cadena);
 
  return EXIT_SUCCESS;
}

Hello, when I compile the above code, give me an error, in line "struct tm *t2, type isn't correct:missing keyword typedef" but it's a correct code, because "struct tm " is defined on "time.h", any help?? :?

Jenna

Topic locked, because it violates our forum rules !

Please respect the forum rules, you have accepted with registering here !

C::B is an IDE not a compiler !

http://wiki.codeblocks.org/index.php?title=FAQ#Q:_What_Code::Blocks_is_not.3F

This forum/website is not a general programming forum !!