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 6901865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:43:37+00:00 2026-05-27T07:43:37+00:00

Im doing a game in C on console application and I need to print

  • 0

Im doing a game in C on console application and I need to print a timer while the user play the game at the same time, I don’t know how to program that well, actually I just start using this compiler so I don’t know a lot of multithreads and stuff but this is the far as I get, here is an example of two functions the first one is the “timer” and the second its just some question, my doubt is if I can run these 2 functions at the same time, and how I can print the timer while I can answer those 2 question without interrupting the console.

EXAMPLE:

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


DWORD WINAPI Timer(int limit)
{
    int secs = 1;
    time_t unix;

    struct tm * timeinfo;
    time(&unix);
    timeinfo = localtime(&unix);

    int t1 = timeinfo->tm_sec;
    int t2 = timeinfo->tm_sec;
    int i = 0;

    while(1 == 1)
    {
       time(&unix);
       timeinfo = localtime(&unix);
       if((t1 + i)  == timeinfo->tm_sec)
       {
              system("cls");
              printf("time left %d seconds\n", timeinfo->tm_sec - t2 - limit);
              i++;
       }
       if(timeinfo->tm_sec >= (t1 + limit))
       {
            break;
            printf("Your time its done");
       }
    }
    return 0;
}

DWORD WINAPI Questionary()
{
    puts("testing\n\n");

    int age, height;
    printf("Please write your age: ");
    scanf("%d", &age);
    printf("Please write your height: ");
    scanf("%d", &height);
    printf("\n\nThe numbers written are %d y %d", age, height);
    return NULL;
}
int main()
{
    int i, limit;
    HANDLE tempo;
    HANDLE questions;
    DWORD ThreadId;

    printf("\nHow much time would you like for your timer countdown? ");
    scanf("%d", &limit);

    //Funcion Handle
    questions= CreateThread(NULL,0,Questionary,1,0,&ThreadId);
    WaitForSingleObject(preguntas,INFINITE);

    tempo= CreateThread(NULL,0,Timer(limit),1,0,&ThreadId);
    WaitForSingleObject(tiempofinal,limit*40);


    return 0;
}
  • 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-05-27T07:43:38+00:00Added an answer on May 27, 2026 at 7:43 am

    You can print the question, and instead of waiting for an answer in a blocking call (like scanf) you loop while polling for new input, and use ANSI escape codes to print the time at another position.

    Something like the following pseudo-code:

    print(question)
    while (current_time < timer_end)
    {
        if (have_input())
            break
    
        save_current_cursor_position()
        move_cursor_position(x, y)
        print(timer)
        restore_saved_cursor_position()
    
        very_short_sleep()
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, so I'm doing an html5 canvas game, and I need to draw resized
im doing a level editor for my game and i need to save the
I am programming a simple C# console application. The spec is: A game consists
I'm doing a little beginner c++ program based on the game of snap. When
I want to get started doing some game development using Microsoft's XNA. Part of
I'm doing a chess game. In there, I want to move an element with
Continuing my quest of learning Java by doing a simple game, i stumbled upon
I'm creating a game with points for doing little things, so I have a
Doing my first SL4 MVVM RIA based application and i ran into the following
I know the title's a bit wordy, but I don't know how else to

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.