Author Topic: <time.h>  (Read 10383 times)

flamingo

  • Guest
<time.h>
« on: August 04, 2011, 06:20:56 pm »
Code
#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?? :?
« Last Edit: August 04, 2011, 06:24:28 pm by flamingo »

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: <time.h>
« Reply #1 on: August 04, 2011, 06:38:06 pm »
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 !!