[ back to toc ]

c code for get system running time

Date: 2002/04/07 13:41

Q:
MR.SAWE
Thanks for the reply.i really admire your volunteer answer,
i the same regard i need little Clarification.
i got time and date using time(),getdate().
my problem is time that displayed is STATIC.IT DOES NOT CHANGE
AS IN WATCH.i need to display time as in electronic watch.
i.e it should change in every second.is it possible to do with C?,
with other logic present in the project.i had seen this
in some software like TALLY that display the running time.
when i use the following logic.,
main()
{timec();
/*OTHER LOGICS*/
}
timec()
{ tim4=time(tim3);
tim5=&tim4;
s2=ctime(tim5);
printf("%s",s2);
while(!kbhit())
timec();
return;
}
it works as i expected.but after 4sec the program was
abnormally terminated.with following message.,
scanf:floating point formats not linked.
Abnormal program termination.
also a message box appear with
the program tried to execute an invalied instruction
fault location 5A7E:257E--some hex numbers
interrupt service:None
so please provide me with c-code or logic for the same.
thank in advance.
A:
You ask more than one expert and compare the result! Fine, and I do not
mind. Some experts may do however, thus better pay attention not to title
MR SAWE as Mr. Verhas, because that is me :-)

Your code is boguous. Sorry, to say that but here it is why:

timec()
{ tim4=time(tim3);
tim5=&tim4;
s2=ctime(tim5);
printf("%s",s2);
while(!kbhit())
timec();
return;
}

the function timec starts and prints the time and after doing some things
it calls itself. Then it does it again and calls itself, unless a key is
pressed. However the key is not pressed and the function is calling itself
endlessly. Or more precisely: not endlessly: until the stack overflows. If
you do not compile it with options that make the generated code checking
the stack overflow then the program grabbles the memory totally and any,
literally any error can happen. Even rebooting the machine if you use
Win95/98/ME and not some NT based system, UNIX or Linux.

Regards,
Peter

[ back to toc ]