-
Notifications
You must be signed in to change notification settings - Fork 0
Libft
Bilge Akpulat edited this page Feb 4, 2025
·
1 revision
- #include <stdio.h> → inside here lies printf function
- “” → using a non standart library that is manually created
- <> → used in standart libraries (unistd.h or stdio.h)
- .h file → header file
- #include “library.h” → include the header file
- we can have a library inside a library.
- gcc -o app main.c library.c → this line will give us an executable file called app.
- ./app → runs app
- gcc -o app library.c main.c → works the same way.
#include <stdio.h>
#include "library.h"
int main(void)
{
printf("%d + %d = %d\n", 4, 5, add(4,5));
printf("%d - %d = %d\n", 10, 7, sub(10,7));
return (0);
}
int add(int x, int y);
int sub(int x, int y);
{
return (x + y);
}
int sub(int a, int b)
{
return (a - b);
}
Source: https://www.youtube.com/watch?v=x8gsHFBW7zY
1. Include guard
An include guard prevents a header file from being included multiple times in a single compilation unit, which can lead to errors.
Example:
#ifndef MYLIBRARY_H
#define MYLIBRARY_H
// Header file content
#endif // MYLIBRARY_H