C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 25th, 2002, 11:48 AM
desmondkenny desmondkenny is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2002
Location: Galway, Ireland
Posts: 4 desmondkenny User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy using time.h to loop until reaching a user-specified time

hey all....this is a snippet of code which I am going to use to call a function called trace(), which traceroute's to a specified host. what I want to do here is traceroute continuously until a user-specified time.

this code is not returning the right times, and no matter what time I enter in, the program says it is roughly twice what the current time is and the difference is always 1024 seconds.

have I got the types right? there is probably something small I'm missing.

this will take some knowledge of <time.h> to solve.


#include<sys/time.h>

int option,
quit = 1,
temp1 = 0,
temp2 = 0;

double difference = 0;

time_t stoptime ;
time_t now;

struct tm stop;

now = time(NULL);

while(quit != 0)
{
printf("Please enter option.\n\n");
printf("1 Conduct a fixed number of Traceroutes.\n");
printf("2 Conduct Traceroutes Until a specific Time.\n");
printf("3 Quit\n\n\n");
scanf("%d", &option);

switch(option)
{
case 1 rintf("Please enter the time you would like to run Traceroute until.\n\n");

printf("\nYear: YYYY\n");
scanf("%d", &temp1);
stop.tm_year = temp1 - 1900;
printf("\nMonth: 1-12\n");
scanf("%d", &temp2);
stop.tm_mon = temp2 - 1;
printf("\nday of the month: 0-31\n");
scanf("%d", &stop.tm_mday);
printf("\nhour (24hour clock):\n");
scanf("%d", &stop.tm_hour);
printf("\nminute:\n");
scanf("%d", &stop.tm_min);
printf("\nsecond:\n");
scanf("%d", &stop.tm_sec);

if(mktime(&stop) == -1)
{
printf("Error getting time.\n");
}
stoptime = mktime(&stop);
now = time(NULL);
printf("stop = %d\n", &stoptime);
printf("now = %d\n", &now);
difference = difftime(now, stoptime);
printf("difference in seconds: %f.\n", &difference);

/*
for(; now < stoptime; now = time(NULL))
{
trace(ip);
}
quit = 0;
*/

break;

Reply With Quote
  #2  
Old February 25th, 2002, 01:38 PM
desmondkenny desmondkenny is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2002
Location: Galway, Ireland
Posts: 4 desmondkenny User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking

well, I'm a moron, don't bother replying, I figured it out.....I'm an idiot!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > using time.h to loop until reaching a user-specified time

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap