I'm a little new to C, and I'm having problems with the project I'm currently working on. Essentially, I have the following files: main.c, alarm.c, alarm.h
I have a structure declaration in alarm.c that looks like this:
#define STRLEN 150; struct alarmparams { char time[STRLEN]; char duration[STRLEN]; char snooze[STRLEN]; char port[STRLEN]; };
In main.c, I have:
#include <stdio.h> #include <string.h> #include "alarm.h" int main(int argc, char *argv[]) { struct alarmparams params; printf("%s, %s\n", params.time, params.duration); }
And in alarm.h I have:
struct alarmparams;
Right now, when I go to compilation, I get the following error:
error: storage size of 'params' isn't known
I looked at other posts about this error, so I already worked a bit on this. I also tried some of the suggested solutions, and I either got the same error, or I got more on it. I don’t understand how to fix this.
Is there something I am missing? Am I announcing something wrong?
In general, structures should be declared in the header file or c file? Or does it even matter? What is the difference between:
struct foo {...};
and
typedef struct foo {...};
source share