This C library is a result of 3 of 42 school projects:
libftft_printfget_next_line
The goal was to recode some of the well known and used public C libraries functions as well as some others. More detailed info below and in their own Readme files.
The project is compiled by using Makefile:
make / make all # to compile the library
make clean # to delete the temporary files
make fclean # to delete the temporary files + the compiled library
make re # to do make fclean and make all togetherTo use the functions from the library in your own project, add this include in your files:
#include "libft.a"[BONUS VERSION]
My takes on public C library functions:
int ft_isalpha(int c);
int ft_isalnum(int c);
int ft_isascii(int c);
int ft_isdigit(int c);
int ft_isprint(int c);
int ft_atoi(const char *str);
size_t ft_strlen(const char *s);
int ft_toupper(int c);
int ft_tolower(int c);
void ft_bzero(void *s, size_t n);
void *ft_memset(void *s, int c, size_t n);
void *ft_calloc(size_t nmemb, size_t size);
int ft_strncmp(const char *s1, const char *s2, size_t n);
char *ft_strnstr(const char *haystack, const char *needle, size_t n);
char *ft_strchr(const char *s, int c);
char *ft_strrchr(const char *s, int c);
void *ft_memchr(const void *s, int c, size_t n);
int ft_memcmp(const void *s1, const void *s2, size_t n);
void *ft_memcpy(void *dest, const void *src, size_t n);
void *ft_memmove(void *dest, const void *src, size_t n);
char *ft_strdup(const char *src);
size_t ft_strlcat(char *dst, const char *src, size_t dsize);
size_t ft_strlcpy(char *dst, const char *src, size_t dsize);Not public C library functions:
char *ft_itoa(int n);
void ft_putchar_fd(char c, int fd);
void ft_putendl_fd(char *s, int fd);
void ft_putnbr_fd(int n, int fd);
void ft_putstr_fd(char *s, int fd);
char **ft_split(char const *s, char c);
void ft_striteri(char *s, void (*f)(unsigned int, char*));
char *ft_strjoin(char const *s1, char const *s2);
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
char *ft_strtrim(char const *s1, char const *set);
char *ft_substr(char const *s, unsigned int start, size_t len);And for the bonus part: functions handling linked lists based on this structure:
struct s_list
{
void *content;
struct s_list *next;
} t_list;t_list *ft_lstnew(void *content);
void ft_lstadd_front(t_list **lst, t_list *new);
int ft_lstsize(t_list *lst);
t_list *ft_lstlast(t_list *lst);
void ft_lstadd_back(t_list **lst, t_list *new);
void ft_lstdelone(t_list *lst, void (*del)(void*));
void ft_lstclear(t_list **lst, void (*del)(void*));
void ft_lstiter(t_list *lst, void (*f)(void *));
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));[BONUS VERSION]
A recode of classic printf() from stdio.h.
I chose to battle the infamous BONUS version which includes not only handling basic data type conversions:
%cfor character%sfor string%pfor pointer%dfor decimal%ifor integer%ufor unsigned integer%xfor hexadecimal in lowercase%Xfor hexadecimal in uppercase%%for % sign
but also:
-flag for left padding0flag for zero padding.flag for precision#flag for hex prefix(space)flag for space+flag for explicit +- field minimum width
It was tough, but I am really proud at myself and I learned so much from that. :)
[BONUS VERSION]
A function that returns a line read from a file descriptor.
- Repeated calls (e.g., using a loop) to the
get_next_line()function should let you read the text file pointed to by the file descriptor, one line at a time. - The function should return the line that was read.
If there is nothing left to read or if an error occurs, it should return
NULL.
- Feel free to adjust the
BUFFER_SIZEdirectly in theget_next_line.h. It is better when it is not too small (10 bytes and less) if you plan to read big files or long lines, because the process can be very time consuming with a small buffer. - The function returns
NULLwhen handedBUFFER_SIZE <= 0and/or invalidfdargument. - The function can accept
stdinas input. - The function can process multiple
fdin one program simultaneously. - Each call reads one line, for reading more, call the function repeatedly.
- To avoid undefined behaviour: do not modify the file associated with the file descriptor between calls when the end of file was yet not reached. Also do not put a binary file as an input.
Note: it is possible to change the separator character from \n to something else completely (f. e. space). So with a little adjustment of the code the function can be used in other ways.
When doing other projects I recoded and added some other useful functions:
int ft_abs(int value);
long ft_atol(const char *str);
int ft_count_digits(int n);
int ft_islower(int c);
int ft_isupper(int c);
int ft_putchar(char c);
void ft_putendl(char *s);
int ft_putnbr(int n);
int ft_putstr(char *s);
int ft_sqrt(int nb);
void ft_strtoupper(char *s);
void ft_strtolower(char *s);Simona Sucha
(also known as ssucha or vincent_syma)
Python & C · Developer, Software Tester · 42 student
🖥️ GitHub: https://github.com/vincent-syma/
🔗 LinkedIn: https://www.linkedin.com/in/simona-such%C3%A1-5a1b1928b
✉️ Email: vincent.f.syma@email.cz