Sponsored Content
Full Discussion: Helpm with time function
Homework and Emergencies Homework & Coursework Questions Helpm with time function Post 302988315 by RudiC on Friday 23rd of December 2016 11:47:05 AM
Old 12-23-2016
Your specification is not too clear, and the code doesn't help understanding nor interpreting .
It is always beneficial to show WHAT exactly "doesn't work well". A few comments that jump to mind looking at your code :
- where is $7 used for computations?
- milkmonth and milkday will not have correct values as the substr parameters are wrong and could be moving.
- lastmilk is undefined for the first line, and not reset if $5 changes. This may be intended behaviour, though.
- endmilk is never used; why not drop it entirely?
- as startmilkdiff is the only variable in the printf stament, three %f format specifiers are redundant.
- as correspondent $5 values are NOT in sequence, you'd better work with arrays, or do a sort beforehand.

EDIT:
- plus, the mktime function requires 6 or 7 parameters; you supply 4 only.
- you want to output the difference in days, but calculate and print second values only.

Last edited by RudiC; 12-23-2016 at 01:15 PM..
 

10 More Discussions You Might Find Interesting

1. Programming

C time in milliseconds function.

I need a c function which return the time in: hour min sec and mil sec I am writing on unix os. (3 Replies)
Discussion started by: kamil
3 Replies

2. Programming

find CPU Time for a function (subsecond precision)

Hi, I need to time a certain function in my C/C++ code and I am experiencing some difficulties. I timed it using wallclock time so I know that it takes approximately 500-600 microseconds with gettimeofday(&start, NULL); // my function call gettimeofday(&end, NULL); answer = (end.tv_sec -... (2 Replies)
Discussion started by: zynnel
2 Replies

3. Shell Programming and Scripting

time function

Hi, I would like to display the exact time taken to complete running a particular tool or function or program to user I don't know the exact time functions in unix, please help me thanks in advance Example: $test.ksh output should be The... (10 Replies)
Discussion started by: hsekol
10 Replies

4. Programming

function time

Hello I have problem with function 'time' to test my program for file copying . How to run the function in my source code ? I try something like that: system("time"); < -- but this don't working (2 Replies)
Discussion started by: scotty_123
2 Replies

5. Shell Programming and Scripting

Nawk Time Function

Hi All, I am using solaris and nawk. Is there any time function in nawk which is simliar to the shell `date` function ? Can any experts show any examples? (4 Replies)
Discussion started by: Raynon
4 Replies

6. Shell Programming and Scripting

Unix function to calcuate the difference in time

HI , I need to get the timedifference between two values... which funcation will help eg: difference betweem 19:22 and 19:43 should give 21 mins (2 Replies)
Discussion started by: savitha
2 Replies

7. UNIX for Dummies Questions & Answers

time function

hello everybody! i want to post a question. So, I use the command 'time a.out' to time the duration of the program a.out. The return value of this function was: real 0m4.116s user 0m4.112s sys 0m0.016s What i want is! I try to find a way to get (NOT manually) the value of real time.... (2 Replies)
Discussion started by: nicos
2 Replies

8. Red Hat

lightweight function for measuring time ( better than clock_getime )

HI I have a Red Hat Enterprise with Real Time kernel. Are you aware if there are C functions for this kernel or some code/library for this OS for measuring time more lightweight than clock_gettime and gettimeofday? THe hardware I have is NUMA. Reading forums I found gethrtime but it is... (1 Reply)
Discussion started by: manustone
1 Replies

9. Shell Programming and Scripting

/usr/bin/time Shell Scripting Function

Hello, I have made a Linux Shell Script that downloads 6 files from the Internet and then deletes them. Now i want to use the function "/usr/bin/time" and "bc" to calculate how long the avergate run time for the shell script is. I therefore need to do it 100 times. My shell script code is below: ... (6 Replies)
Discussion started by: solo2
6 Replies

10. OS X (Apple)

'time' does NOT work on a function in 'dash'.

Hi guys and gals... I am writing a piece of code that is dash compliant and came across this error. I have put it in the OSX section as that is what I am using. I have no idea what the 'dash' version is but was installed about 6 months ago. MBP, OSX 10.12.6, default terminal running dash on... (4 Replies)
Discussion started by: wisecracker
4 Replies
mktime(3C)						   Standard C Library Functions 						mktime(3C)

NAME
mktime - converts a tm structure to a calendar time SYNOPSIS
#include <time.h> time_t mktime(struct tm *timeptr); DESCRIPTION
The mktime() function converts the time represented by the tm structure pointed to by timeptr into a calendar time (the number of seconds since 00:00:00 UTC, January 1, 1970). The tm structure contains the following members: int tm_sec; /* seconds after the minute [0, 60] */ int tm_min; /* minutes after the hour [0, 59] */ int tm_hour; /* hour since midnight [0, 23] */ int tm_mday; /* day of the month [1, 31] */ int tm_mon; /* months since January [0, 11] */ int tm_year; /* years since 1900 */ int tm_wday; /* days since Sunday [0, 6] */ int tm_yday; /* days since January 1 [0, 365] */ int tm_isdst; /* flag for daylight savings time */ In addition to computing the calendar time, mktime() normalizes the supplied tm structure. The original values of the tm_wday and tm_yday components of the structure are ignored, and the original values of the other components are not restricted to the ranges indicated in the definition of the structure. On successful completion, the values of the tm_wday and tm_yday components are set appropriately, and the other components are set to represent the specified calendar time, but with their values forced to be within the appropriate ranges. The final value of tm_mday is not set until tm_mon and tm_year are determined. The tm_year member must be for year 1901 or later. Calendar times before 20:45:52 UTC, December 13, 1901 or after 03:14:07 UTC, January 19, 2038 cannot be represented. Portable applications should not try to create dates before 00:00:00 UTC, January 1, 1970 or after 00:00:00 UTC, January 1, 2038. The original values of the components may be either greater than or less than the specified range. For example, a tm_hour of -1 means 1 hour before midnight, tm_mday of 0 means the day preceding the current month, and tm_mon of -2 means 2 months before January of tm_year. If tm_isdst is positive, the original values are assumed to be in the alternate timezone. If it turns out that the alternate timezone is not valid for the computed calendar time, then the components are adjusted to the main timezone. Likewise, if tm_isdst is zero, the origi- nal values are assumed to be in the main timezone and are converted to the alternate timezone if the main timezone is not valid. If tm_isdst is negative, mktime() attempts to determine whether the alternate timezone is in effect for the specified time. Local timezone information is used as if mktime() had called tzset(). See ctime(3C). RETURN VALUES
If the calendar time can be represented in an object of type time_t, mktime() returns the specified calendar time without changing errno. If the calendar time cannot be represented, the function returns the value (time_t)-1 and sets errno to indicate the error. ERRORS
The mktime() function will fail if: EOVERFLOW The date represented by the input tm struct cannot be represented in a time_t. Note that the errno setting may change if future revisions to the standards specify a different value. USAGE
The mktime() function is MT-Safe in multithreaded applications, as long as no user-defined function directly modifies one of the following variables: timezone, altzone, daylight, and tzname. See ctime(3C). Note that -1 can be a valid return value for the time that is one second before the Epoch. The user should clear errno before calling mktime(). If mktime() then returns -1, the user should check errno to determine whether or not an error actually occurred. The mktime() function assumes Gregorian dates. Times before the adoption of the Gregorian calendar will not match historial records. EXAMPLES
Example 1 Sample code using mktime(). What day of the week is July 4, 2001? #include <stdio.h> #include <time.h> static char *const wday[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "-unknown-" }; struct tm time_str; /*...*/ time_str.tm_year = 2001 - 1900; time_str.tm_mon = 7 - 1; time_str.tm_mday = 4; time_str.tm_hour = 0; time_str.tm_min = 0; time_str.tm_sec = 1; time_str.tm_isdst = -1; if (mktime(&time_str)== -1) time_str.tm_wday=7; printf("%s ", wday[time_str.tm_wday]); BUGS
The zoneinfo timezone data files do not transition past Tue Jan 19 03:14:07 2038 UTC. Therefore for 64-bit applications using zoneinfo timezones, calculations beyond this date may not use the correct offset from standard time, and could return incorrect values. This affects the 64-bit version of mktime(). ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe with exceptions | +-----------------------------+-----------------------------+ SEE ALSO
ctime(3C), getenv(3C), TIMEZONE(4), attributes(5), standards(5) SunOS 5.11 1 Nov 2003 mktime(3C)
All times are GMT -4. The time now is 05:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy