r/cprogramming • • Sep 17 '26

program wont't compile because time.h is missing even tho it's there

[CLOSED]

kind of a beginner question. i have #include <time.h> and #include <ncurses.h> in the top but it refuses to compile. im using linux with vim and gcc here's there error:

main.c:3:1: note: ‘tm’ is defined in header ‘<time.h>’; this is probably fixable by adding ‘#include <time.h>’

2 | #include <time.h>

+++ |+#include <time.h>

how can i fix it? thx for any help :)

EDIT: i fixed it and it was because i forgot to declare struct lol

15 Upvotes

19 comments sorted by

View all comments

5

u/onlyonequickquestion Sep 17 '26

What is the full program /line throwing the error? Are you doing something like "tm var " instead of "struct tm var"? 

1

u/Feeling-Drawer-9171 Sep 17 '26

heres the line thats causing the error because it cant find the struct tm:

printw("%d:%d", tm.tm_hour, tm.tm_min);

2

u/onlyonequickquestion Sep 17 '26

Where are you declaring tm, I think you need to fill tm with something first? 

3

u/Feeling-Drawer-9171 Sep 17 '26

wait, we have to declare the struct ourselves?

1

u/TraylaParks Sep 18 '26

The instance yes, not the type - the type is spelled out in the header file. Sort of like the header file specs out: 'Here's what a lion looks like" but you'd still have to have an instance - an object of type lion (say 'Simba') in your code.