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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:34:22+00:00 2026-05-26T23:34:22+00:00

In timer.c I have typedef struct Timer { int startTicks; int pausedTicks; int paused;

  • 0

In timer.c I have

typedef struct Timer {

    int startTicks;
    int pausedTicks;

    int paused;
    int started;

} Timer;

void Init( Timer *t )
{
    t->startTicks = 0;
    t->pausedTicks = 0;
    t->paused = 0;
    t->started = 0;
}

What do i need to do in main.c to make use of this struct and functions in that file?

  • 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-26T23:34:22+00:00Added an answer on May 26, 2026 at 11:34 pm

    In general, .c files contain definitions and .h files contain declarations. A better approach would be to keep your definitions in a header:

    //timer.h
    #ifndef TIMER_H //include guard
    #define TIMER_H
    
    typedef struct Timer { //struct declaration
    
        int startTicks;
        int pausedTicks;
    
        int paused;
        int started;
    
    } Timer;
    
    void Init( Timer *t ); //method declaration
    
    #endif
    
    
    //timer.c
    #include "timer.h"
    
    void Init( Timer *t ) //method definition
    {
        t->startTicks = 0;
        t->pausedTicks = 0;
        t->paused = 0;
        t->started = 0;
    }
    
    //main.c
    #include "timer.h"  //include declarations
    int main()
    {
        Timer* t = malloc(sizeof(Timer));
        Init(t);
        free(t);
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: Typedef struct SPro{ int arrivalTime; char processName[15]; int burst; } PRO; I have
I have a structured defined as typedef struct{ char string1 char string2 int number1
I have a set of structs, defined as follows: typedef struct { int index;
I have a struct as below typedef struct _someStruct { int V1; char V2[10];
I have a struct with an array of 100 int (b) and a variable
OK, I hope I explain this one correctly. I have a struct: typedef struct
I have following method in the c code. void add(int number) { Node node1;
I've a weird problem with malloc. I have this typedefs: typedef struct buffer {
#include <stdio.h> #include <pthread.h> #include <time.h> #include <stdlib.h> typedef struct pr_struct{ int owner; int
/*language C code*/ #include windows.h typedef struct object_s { SRWLOCK lock; int data; }

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.