ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
ctime() creates a printable date-time string which includes a newline character.
Code:
The ctime() function adjusts the time value for the current time zone, in the same
manner as localtime(). It returns a pointer to a 26-character string of the form:
Thu Nov 24 18:22:48 1986\n\0
Oh wait, you are probably concerned about the formatting itself. My bad.
Last edited by dwhitney67; 08-02-2010 at 10:11 AM.
When compiling with -Wall, your code gives warnings
Code:
fortyfourgalena@desktop1:~/progs/c/lq823035$ gcc -Wall lq823035.c -o lq823035
lq823035.c: In function ‘main’:
lq823035.c:29: warning: control reaches end of non-void function
lq823035.c: In function ‘read_utmp’:
lq823035.c:48: warning: assignment from incompatible pointer type
lq823035.c: In function ‘reload_utmp’:
lq823035.c:56: warning: implicit declaration of function ‘read’
fortyfourgalena@desktop1:~/progs/c/lq823035$
Not said that this is the problem, but the incompatible pointer type is worrying.
And this is the output
Code:
fortyfourgalena@desktop1:~/progs/c/lq823035$ ./lq823035
fortyfourgalena tty9 Mon Aug 2 16:59:04 2010
Mon Aug 2 16:59:04 2010
:0
fortyfourgalena pts/0 Mon Aug 2 17:15:53 2010
Mon Aug 2 17:15:53 2010
:0.0
fortyfourgalena pts/1 Mon Aug 2 17:17:20 2010
Mon Aug 2 17:17:20 2010
:0.0
fortyfourgalena@desktop1:~/progs/c/lq823035$
the following is my output:
plz put you uname output...I think the problem only appears in 64-bit OS. for ctime() expects a pointer to 64bit, but i give it a pointer to 32bit, so the following 32bit is included in, so produce the wrong result.
guest@bequiet:~/workspaceCpp/PGMPractise$ uname -a
Code:
Linux bequiet 2.6.31-14-generic #48-Ubuntu SMP Fri Oct 16 14:05:01 UTC 2009 x86_64 GNU/Linux
guest@bequiet:~/workspaceCpp/PGMPractise$ make iwho
Code:
cc iwho.c -o iwho
iwho.c: In function ‘read_utmp’:
iwho.c:59: warning: assignment from incompatible pointer type
guest@bequiet:~/workspaceCpp/PGMPractise$ ./iwho
Code:
guest tty7 Mon Aug 2 22:52:51 2010
Fri Jul 16 16:22:27 11813086
:0
guest pts/0 Mon Aug 2 22:55:20 2010
Wed Feb 18 04:40:56 81151660
:0.0
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.