Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7746703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:20:48+00:00 2026-06-01T10:20:48+00:00

I am trying to create a loop function based on the time. After the

  • 0

I am trying to create a loop function based on the time. After the iteration, it will print every 60 second “60 second passed”. But this code result me in couple of “60 second passed” while actually me watch does not even showing 1 minute already..
I tried below, but I am expecting it to show me this information, but it does not (only the first couple of lines of iteration. afterwards not..)

Can anyone help in this matter? Thank you

#include <stdio.h>
#include <time.h>

int main()
{
time_t start,stop;
start = time(NULL);
time(&start);
int iteration, i;
    for (iteration = 1; iteration <= 500; iteration++) {
            for (i = 0; i <= 50; i++) {
                     printf("looping while waiting 60 second..\n");

             }
            stop = time(NULL);
            int diff = difftime(start, stop);
            if (diff % 60 == 0) {
                     printf("60 second passed..");}
            }

    return 1;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:20:49+00:00Added an answer on June 1, 2026 at 10:20 am

    difftime and the following code are likely being executed multiple times before even one second has passed. As a result, difftime will return a value < 1, which is truncated to 0 by your implicit cast. And of course 0 % 60 == 0.

    EDIT:

    You might consider something like:

    start = time(NULL);
    for(; /* some condition that takes forever to meet */;) {
        // do stuff that apparently takes forever.
        stop = time(NULL);
        double diff = difftime(stop, start);
        if (diff >= 60) {
            printf("60 seconds passed...");
            start = time(NULL);
        }
    }
    

    Also note that in your example code, start and stop should be flipped in the call to difftime.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a function that will loop through an array of various
I am trying to create a loop that will perform a series of analyses.
Im trying to create a loop of items like this... for each (var btn:Object
I'm trying create this function such that if any key besides any of the
Based on this question which was closed rather quickly: Trying to create a program
I am trying to create a function which will load a whole lot of
Im trying to create a function, that will return a mysql query, which i
I'm trying to solve this newbie puzzle: I've created this function: def bucket_loop(htable, key):
I'm trying to create a loop that creates a series of objects that contains
I'm trying to create a loop than continues to take input until the input

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.