问题
I tried to make my own header file but it doesn't work vim
says
wget.h:2:2: error: invalid preprocessing directive #ifndef__WGET_H__
wget.h:3:2: error: invalid preprocessing directive #define__WGET_H__
wget.h:7:2: error: #endif without #if
My code is this:
//wget header file
#ifndef__WGET_H__
#define__WGET_H__
int my_wget (char web_address[]);
#endif /*__WGET_H__*/
it seems fine to me (the examples I have read are much alike with mine) and I don't know what went wrong. Any ideas?
回答1:
Everything is right , just the space was missing.
#ifndef __WGET_H__
#define __WGET_H__
int my_wget (char web_address[]);
#endif __WGET_H__
You would generally use the above , in header files , because , in your project , if you happen(by accident) to include the same header multiple times , then writing the header like this will make sure , that it includes the header only once.
回答2:
You must leave a space between the preprocessor keyword and the label:
#ifndef __WGET_H__
#define __WGET_H__
回答3:
Change:
#ifndef__WGET_H__
#define__WGET_H__
to
#ifndef __WGET_H__
#define __WGET_H__
(note the space between #ifndef
and __WGET_H__
)
回答4:
You need to leave a space between a preprocessor keyword (e.g. #define
) and the label (i.e. __WGET_H__
). In other words:
#ifndef __WGET_H__
#define __WGET_H__
will work.
来源:https://stackoverflow.com/questions/15352253/how-do-i-make-my-own-header-file-in-c