LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-01-2004, 10:46 AM   #1
azi
LQ Newbie
 
Registered: Nov 2003
Posts: 17

Rep: Reputation: 0
Weired ctime() asctime() output


Erm the code firs :} :

Code:
#include <stdio.h>
#include <utmp.h>
#include <string.h>
#include <time.h>
 
int main(  )
 
{
 
 
 
 
        struct lastlog vsebina_lastloga ;
        FILE *datoteka ;
 
        if ((datoteka = fopen("/var/log/lastlog", "r+")) == NULL) 
 
        {
                fprintf(stderr,"Napaka pri odpiranju datoteke\n");
                return (9);
 
        }
 
 
                struct tm faketime ;
 
                faketime.tm_sec = 40; 
                faketime.tm_min = 54;     
                faketime.tm_hour = 21 ;
                faketime.tm_mday = 12 ;
                faketime.tm_mon = 3;   
                faketime.tm_year = 304 ;        
                faketime.tm_wday =  5 ; 
                faketime.tm_yday = 300 ;
 
 
        datoteka = fopen("/var/log/lastlog", "r+") ;
        fread(&vsebina_lastloga, sizeof(struct lastlog), 1, datoteka);
 
        printf("%s\n%s\n" , asctime(&faketime), ctime(&vsebina_lastloga.ll_time)) ;
 
        fclose(datoteka) ;
        return 0 ;
 
}
Now what i don't understand is how can this printf " printf("%s\n%s\n" , asctime(&faketime), ctime(&vsebina_lastloga.ll_time)) " prints two IDENTICAL values like this :
bash-2.05b# ./a.out
Fri Apr 12 21:54:40 2204

Fri Apr 12 21:54:40 2204

Can somebody explain me how can this succede ?
 
Old 07-01-2004, 04:48 PM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
This code:
Code:
#include <stdio.h>
#include <time.h>    
#include <errno.h>
int main(int argc, char *argv[]  )

{   
    struct tm faketime ;
    time_t ll_time=86400 * 2000;
    faketime.tm_sec = 40;
    faketime.tm_min = 54;
    faketime.tm_hour = 21 ;
    faketime.tm_mday = 12 ;
    faketime.tm_mon = 3;
    faketime.tm_year = 304 ;
    faketime.tm_wday =  5 ;
    faketime.tm_yday = 300 ;     
     printf("%s\n", asctime(&faketime) );
     printf("errno =%d\n", errno);
     printf("%s\n" , ctime(&ll_time)) ;
     printf("errno =%d\n", errno);
     return 0 ;
}
Gives me this output:

Fri Apr 12 21:54:40 2204

errno =0
Mon Jun 23 18:00:00 1975

errno =0

You do know that the implementation of asctime creates allocates memory and creates a temporary struct tm
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Squid: weired error. wwnexc Linux - Networking 7 03-02-2006 05:58 AM
ctime of /etc/samba/smbpasswd different ddaas Linux - Security 0 07-04-2005 01:42 AM
mtime/ctime changed on directory entries stardot Linux - Security 2 11-29-2004 10:44 PM
Weired iptables port forwarding wrexy Debian 0 09-04-2004 04:11 PM
weired problem with php and mysql dsiguy Linux - General 0 03-05-2003 02:24 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration