Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. i don't know why both result same~

i don't know why both result same~

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jung Seng Won
    wrote on last edited by
    #1

    #include <time.h> #include<stdio.h> #include <conio.h> #include <stdlib.h> #include <Windows.h> void main() { time_t curr, bir; struct tm *curr_tm, *bir_tm; curr = time(NULL); bir = time(NULL); curr_tm = localtime(&curr); bir_tm = localtime(&bir); // printf("%s\n", asctime(curr_tm)); // printf("%s\n", asctime(bir_tm)); bir_tm->tm_year = 83; bir_tm->tm_mon = 11; bir_tm->tm_mday = 26; printf("%s\n", asctime(curr_tm)); printf("%s\n", asctime(bir_tm)); }//main i don't know why printf("%s\n", asctime(curr_tm)); printf("%s\n", asctime(bir_tm)); 's result is same~ definitly curr_tm, bir_tm 's paramata is different~ example) curr_tm = localtime(&curr); bir_tm = localtime(&bir);

    firstly, i am sorry, i am from korea. and i am not good in wriitting english so please understand~ Thank you everyone~

    C CPalliniC 2 Replies Last reply
    0
    • J Jung Seng Won

      #include <time.h> #include<stdio.h> #include <conio.h> #include <stdlib.h> #include <Windows.h> void main() { time_t curr, bir; struct tm *curr_tm, *bir_tm; curr = time(NULL); bir = time(NULL); curr_tm = localtime(&curr); bir_tm = localtime(&bir); // printf("%s\n", asctime(curr_tm)); // printf("%s\n", asctime(bir_tm)); bir_tm->tm_year = 83; bir_tm->tm_mon = 11; bir_tm->tm_mday = 26; printf("%s\n", asctime(curr_tm)); printf("%s\n", asctime(bir_tm)); }//main i don't know why printf("%s\n", asctime(curr_tm)); printf("%s\n", asctime(bir_tm)); 's result is same~ definitly curr_tm, bir_tm 's paramata is different~ example) curr_tm = localtime(&curr); bir_tm = localtime(&bir);

      firstly, i am sorry, i am from korea. and i am not good in wriitting english so please understand~ Thank you everyone~

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      curr_tm = localtime(&curr); bir_tm = localtime(&bir); from the MSDN[^]: gmtime, mktime, and localtime all use a single statically allocated tm structure for the conversion. Each call to one of these routines destroys the result of the previous call. in other words, curr_tm and bir_tm have the same value because they are pointing at the same structure, because localtime returns the same structure each time you call it.

      image processing toolkits | batch image processing

      CPalliniC 1 Reply Last reply
      0
      • J Jung Seng Won

        #include <time.h> #include<stdio.h> #include <conio.h> #include <stdlib.h> #include <Windows.h> void main() { time_t curr, bir; struct tm *curr_tm, *bir_tm; curr = time(NULL); bir = time(NULL); curr_tm = localtime(&curr); bir_tm = localtime(&bir); // printf("%s\n", asctime(curr_tm)); // printf("%s\n", asctime(bir_tm)); bir_tm->tm_year = 83; bir_tm->tm_mon = 11; bir_tm->tm_mday = 26; printf("%s\n", asctime(curr_tm)); printf("%s\n", asctime(bir_tm)); }//main i don't know why printf("%s\n", asctime(curr_tm)); printf("%s\n", asctime(bir_tm)); 's result is same~ definitly curr_tm, bir_tm 's paramata is different~ example) curr_tm = localtime(&curr); bir_tm = localtime(&bir);

        firstly, i am sorry, i am from korea. and i am not good in wriitting english so please understand~ Thank you everyone~

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #3

        From localtime documentation [^] gmtime, mktime, and localtime all use a single statically allocated tm structure for the conversion. Each call to one of these routines destroys the result of the previous call. hence both curr_tm and bir_tm point to the same static struct. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        [my articles]

        In testa che avete, signor di Ceprano?

        1 Reply Last reply
        0
        • C Chris Losinger

          curr_tm = localtime(&curr); bir_tm = localtime(&bir); from the MSDN[^]: gmtime, mktime, and localtime all use a single statically allocated tm structure for the conversion. Each call to one of these routines destroys the result of the previous call. in other words, curr_tm and bir_tm have the same value because they are pointing at the same structure, because localtime returns the same structure each time you call it.

          image processing toolkits | batch image processing

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          Chris Losinger wrote:

          gmtime, mktime, and localtime all use a single statically allocated tm structure for the conversion. Each call to one of these routines destroys the result of the previous call.

          Though the assertion are in fact related, in the OP particular case, IMHO the

          Chris Losinger wrote:

          use a single statically allocated tm structure

          is more relevant than

          Chris Losinger wrote:

          Each call to one of these routines destroys the result of the previous call

          . :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          [my articles]

          In testa che avete, signor di Ceprano?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups