Ask a Question related to UNIX Programming, Design and Development.
-
Matt Churchyard #1
getting time string
I have pieced together some functions to get the current time as a string.
This is used in a logging function and works a few times, but after being
called
more than about 6 times, it causes a core dump.
Is there a better way of getting the time as a string?
my code
--------------------------------------------
time_t *etime; // pointer to unix time
char *stime; // time string
time(etime); // get current unix time
stime = ctime(etime); // convert to string
stime[24] = 0; // remove \n
---------------------------------------------
--
Thanks,
Matt Churchyard
Matt Churchyard Guest
-
SQL generates 'access violation or syntax' error whencompiled into string var ahead of time
I have stumbled across something perplexing and frustrating, and I'm hoping somebody can shed some light here. I have a site with some listings.... -
Maintain query string and somehow auto refresh a pagewith that string intact
I have a drill down where on page one the user selects criteria to narrow down the search for a speicific group of employees(like all hired between... -
Formatting a time field to 24 hour time (Military time) in the Datagrid
Anyone know how to do this? -
Best way to process a string 1 char at a time
John Heim wrote: for ($i = 0; $i < strlen($str); $i++) { strFunction($str{$i}); } is one way. -
Cannot create an object of type 'System.String[]' from its representation 'String[] Array'
Hello, I am designing a .net custom control in VS.net 7.1 and my control exposes an array of strings which are supposed to be the items to show. To... -
Jens.Toerring@physik.fu-berlin.de #2
Re: getting time string
Matt Churchyard <matt@userve.net> wrote:
> I have pieced together some functions to get the current time as a string.
> This is used in a logging function and works a few times, but after being
> called
> more than about 6 times, it causes a core dump.
> Is there a better way of getting the time as a string?> my code
> --------------------------------------------
> time_t *etime; // pointer to unix time
> char *stime; // time stringFrom the man page of time(2):> time(etime); // get current unix time
time returns the time since the Epoch (00:00:00 UTC, Jan-
uary 1, 1970), measured in seconds.
If t is non-NULL, the return value is also stored in the
memory pointed to by t.
In your case etime is an unitialized pointer, which is probably *not*
NULL, but pointing at some random place in memory. Thus time() writes
over this memory and if you're lucky, you get a crash because you
destroyed someting you needed immediately. Either change your code so
that you have
time_t etime;
time( &etime );
or
time_t etime;
etime = time( NULL );
Regards, Jens
--
_ _____ _____
| ||_ _||_ _| [email]Jens.Toerring@physik.fu-berlin.de[/email]
_ | | | | | |
| |_| | | | | | [url]http://www.physik.fu-berlin.de/~toerring[/url]
\___/ens|_|homs|_|oerring
Jens.Toerring@physik.fu-berlin.de Guest



Reply With Quote

