Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using stime( ) in C and compiling using MSF Compiler

Status
Not open for further replies.

hd7106

Programmer
Nov 27, 2002
21
US
Hi,

I wanted to use an example code from Jamsa's book TIP 643 to set date and time exactly one day ahead.
#include <stdio.h>
#include <time.h>

void main(void)
{
time_t seconds;

time( & seconds ); // Get current time

seconds += (time_t) 60 * 60 * 60; // Set date exactly one day ahead

stime( & seconds );

printf(&quot;Current Date and Time is: %s&quot;, ctime(&seconds) );

}

However, when I compile this code using C compiler from Visual Studio 6.0, It does not recognize stime(). I was wondering if there is an alternative function.

H:\CPROGS\JAMSA>cl -o 643 643.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

643.c
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/out:643.exe
/out:643.exe
643.obj
643.obj : error LNK2001: unresolved external symbol _stime
643.exe : fatal error LNK1120: 1 unresolved externals

Hasmukh Daji
 
I am not sure what you mean Richard. As you may notice that I have already used time() to get the current date and time.

Just to give you a quick update - as I learned from Jamsa's C/C++ Bible for Date and Time Functions:

stime() - can be used to set the future time. I think it is a very useful function. Especially, how can you tell if it is the end of the month, without writing array table and the voodoo logic? So with stime() you can check if tommorow is Day 1 of the mointh. By the way the value returned is in seconds as of 1/1/1970. Cool!

ctime() allows you to change the returnd value in seconds to standard Date and Time in text format. Which is great also.

Fortunately this is what I found out as I was testing the above code: There is absolutely nothing wrong with the code, by the way.

I could not compile this code on Win 2K using Visual Studio 6.0 or Visual Studio.NET on XP. It cannot find those functions in the library. I accessed MSDN site for any hits, found lots of academic stuff, but nothing that answered my question.

I also have CYGWIN - Red Hat Linux port of Unix on Win 2K. It's a great product. They did not have these library functions either. Compile fails.

Finally, I also have old SUN Solaris 2.6 system with C/C++ compiler installed. Guess what, it compiled error free.

Luckily my solution was for Solaris platform, so it worked to my benefit. Imagine the added logic I would have to create to figure out if it is the last day of the month or tommorow is 1st day of the month.

I am rather surprised that standard compilers did not pick this up, as they are ANSI library functions.
 
I have cron schedule to reset specific fields to zero within a report data record. These values should be reset before midnight of the 1st day of the month. i.e. 23:59 hrs. on the last day of the month. Although, this code also resets some other counters on a daily basis.

As you can probably imagine, that a single record consists of daily as well as cummulative numbers. The cummulative numbers get exported to another file at the end of the month and then resets all fields within the original to zero.

The question is:
In you C Program, How can you determine, without hard coding anything or without creating array data, tommorow will be the first day of the month. It should use system date and time attributes to establish that.

Again, I have the code tested and working on Solaris system, where it was supposed to execute in the first place. It is alreday promoted to production.

But when I execute the same code against latest Microsoft compiler, it does not recognize stime() librray or ctime() library function. The reason being I strated writing the code on my laptop which has WIN2K as well as CYGWIN using &quot;gcc&quot; compiler. In both instances the compiler barfed.

I am sure this is a common question for any business requirement, indpendent of the platforms.

Hope, this makes it a little clear.
Hasmukh Daji
 
The [tt]stime[/tt] function doesn't seem to do anything, as you add the number of seconds you want manually. Did you try removing the call to [tt]stime[/tt] and see if it works? //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top