![]() |
|
Linux vs. _strdate _strtime |
Michael Jensen
Member #2,870
October 2002
![]() |
I've been using _strdate/_strtime (I include <time.h> of course) in my program to get the date/time (it's nice for the high scores you know) ... it seems to work in windows even with the allegro timer installed. Which is awesome. When I go to compile on debian linux however I get "_strdate was not declared in this scope" along with "_strtime was not declared in this scope" -- are there some other functions I should be using instead for linux?
|
Thomas Fjellstrom
Member #476
June 2000
![]() |
Well, one thing to note, all symbols that start with an underscore are reserved symbols Anyhow, _foo functions in windows are typically just renamed versions of the standard libc methods. Though those functions don't even seem to exist in libc. try strftime, ctime, asctime or strptime instead. note, the first three are c89 and c99 (and another), while the latter is only SUSv2, and POSIX.1-2001. -- |
Kitty Cat
Member #2,815
October 2002
![]() |
char str[32]; /* Will hold the string for the current date/time; must be at least 26 bytes */ ctime_r(time(NULL), str); The normal ctime function is C89, but is not reentrant. It's returned string may be overwritten on subsequent calls. ctime_r is safer. -- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Personally, I'd use strftime. Much safer, and you can easily specify the format. -- |
Michael Jensen
Member #2,870
October 2002
![]() |
google code search is a badass:
I have no idea what this is for, but I got most of that code from analyzing this It works in msvc/gcc on windows, I just have to upload and try it on linux. Thanks for the input guys, it DID help.
|
Thomas Fjellstrom
Member #476
June 2000
![]() |
Or:
-- |
Michael Jensen
Member #2,870
October 2002
![]() |
but I... I don't want that format... however: localtime(time) seems like a neat way access the time... but... dont you have to call localtime(time(NULL)) or at least localtime(time())?
|
Thomas Fjellstrom
Member #476
June 2000
![]() |
Quote: however: localtime(time) seems like a neat way access the time... but... dont you have to call localtime(time(NULL)) or at least localtime(time())? I made a couple mistakes*
-- |
Michael Jensen
Member #2,870
October 2002
![]() |
so my current code now is:
|
BAF
Member #2,981
December 2002
![]() |
You could just "return string(cptime);" to shorten it by another line of code. |
CGamesPlay
Member #2,559
July 2002
![]() |
Or just return cptime and let the compiler convert. -- Ryan Patterson - <http://cgamesplay.com/> |
Michael Jensen
Member #2,870
October 2002
![]() |
dunno what cptime is or how it's formatted, but this is working in msvc/mingw/linux-g++ so I'm happy.
|
Thomas Fjellstrom
Member #476
June 2000
![]() |
cptime is your variable -- |
Michael Jensen
Member #2,870
October 2002
![]() |
oh, so it is.
|
|