user972425
user972425

Reputation: 25

Issue with struct in header

Hi everyone I'm running into problems with placing a c struct in a header file so it can be shared. I haven't found a solution yet that actually compiles without error so I can't figure out what I am doing wrong.

Header File awget.h

#ifdef awget_H
#define awget_H

typdef struct List{
char IPs;
}List;

#endif

Source File awget.c

#include "awget.h"
int main(int argc, char *argv[]) 
{
 List receiveHere;
 struct List sendHere;

 return 0;
}

The first declaration in the source file returns, "error: unknown type name ‘List’". The second declaration returns, "error: storage size of ‘sendHere’ isn’t known".

From what I've been able to gather the first should be a legal declaration, but I'm clearly doing it wrong. I've tried extern and typedefs and read every c struct in header article I could find to try to properly understand how to put a struct in a header to no avail, let alone something that compiled properly.

Can someone either point me in the direction of a proper resource or shed some light on what I have setup incorrectly? Thank you for your time.

Upvotes: 0

Views: 240

Answers (1)

auselen
auselen

Reputation: 28087

1) It is #ifndef, as in 'if not defined' you should use.

Change

#ifdef awget_H

with

#ifndef awget_H

2) It is typedef not typdef.

3) If it is not C++, it must be List sendHere not struct List sendHere.

Upvotes: 6

Related Questions