How do I make my own header file in C?

你离开我真会死。 提交于 2021-02-16 19:36:14

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!