Given a function, let's say atoi, how can I find the header file I should include if I want to use this function ? I'm always get puzzled for that issue. If let me treat function like "atoi" as linux c api, I can put my question in another way as : Is a document for linux c api ?
views:
215answers:
4Man pages. Type man atoi
(or, in general, man <function>
) at your command prompt. It will give you usage information as well as a listing of which headers to include.
Man pages also document programs and commands (find, grep, cd, etc.). Sometimes you may run into a case where a program has the same name as a C function (e.g. write). In that case, you need to direct man to look in the correct section of the manual, section 2 for system calls and section 3 for library functions. You do this by inserting the section number between "man" and the command name: man 2 write
. If you do not know whether a given function is a system call or a library function, try both.
You can learn more about manual pages by typing man man
.
Is a document for linux c api ?
Certainly. The documentation is available as man pages. Type man <function>
in a terminal and enjoy. Which header file you need to include is usually shown at the top.
If you are using ctags and the vim editor and you have set up ctags to scan /usr/include then ctrl-] while you're on the function you want to find takes you to the headerfile!
You can use the following also
whereis <function name>
It will give the path name for the function. Then open the path using vim editor. Then using the "vim" editor you can see the header file.
Example
> whereis atoi
atoi: /usr/share/man/man3/atoi.3.gz
> vim /usr/share/man/man3/atoi.3.gz
----------
----------
.B #include <stdlib.h>