Skip to content

About

Create a library including useful functions in the future projects and help student to understand from the basics of C language.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project has been created as part of the 42 curriculum by sliang

📋 Description

This libft is the milestone 0 subject from Amsterdam Codam (42 curriculmn). The goal is to create a library including useful functions in the future projects and help student to understand from the basics of C language. The required functions include reproducing fucntions from <ctype.h> <stdlib.h> <string.h> and non-standard functions by 42 as well.

Part1 functions

ft_atoi -- Converts the initial portion of the string pointed to by nptr to int. Basically, it converts ASCII string to integer.
ft_bzero -- Set n bytes in memory areas' value as 0.
ft_calloc -- Allocates memory for an array of nmemb elements of size bytes each and returns a pointer to the allocated memory, which is set to 0.
ft_isalnum -- Check if the passing int is alphabet or digit number.
ft_isalpha -- Check if the passing int is alphabet.
ft_isascii -- Check if the passing int is within ascii.
ft_isdigit -- Check if the passing int is digit number.
ft_isprint -- Check if the passing int is printable.
ft_memchr -- Scans the initial n bytes of the memory area pointed to by s for the first instance of c.
ft_memcmp -- Compares n bytes (as unsigned char) of the memory areas s1 and s2.
ft_memcpy -- Copies n bytes from memory area src to memory area dst. If dst and src overlap, behavior is undefined.
ft_memmove -- Copies n bytes from memory area src to memory area dest. The memory areas may overlap. The copy is always done in a nondestructive manner.
ft_memset -- Fill a byte string with a byte value.
ft_strchr -- Returns a pointer to the first occurrence of thencharacter c in the string s.
ft_strdup -- returns a pointer to a new string which is a duplicate of the string s, memory obtained with malloc(3), and be freed with free(3).
t_strlcat -- Concatenates strings respectively. It takes the full size of the buffer (not just the length, NULL included) and guarantee to NUL-terminate the result.
ft_strlcpy -- Copies strings respectively. It take the full size of the buffer (not just the length, NULL included) and guarantee to NUL-terminate the result.
ft_strlen -- Find length of string.
ft_strncmp -- Compare two strings no more than n bytes.
ft_strnstr -- Locate a substring in a string.
ft_strrchr -- Locates the last occurrence of c (converted to a char) in the string pointed to by s.
ft_toupper -- lower case to upper case letter conversion.
ft_tolower -- lower case to upper case letter conversion.

Part2 functions

ft_substr -- Allocates memory (using malloc(3)) and returns a substring from the ’s’. The substring starts at index ’start’ and has a maximum length of ’len’.
ft_strjoin -- Allocates memory and returns a new string, which is the result of concatenating ’s1’ and ’s2’.
ft_strtrim -- Allocates memory and returns a copy of ’s1’ with characters from ’set’ removed from the beginning and the end.
ft_itoa -- Allocates memory (using malloc(3)) and returns a string representing the integer received as an argument. Negative numbers must be handled.
ft_strmapi -- Applies the function f to each character of the string s. A new string is created to store the results from the successive applications of f.
ft_striteri -- Applies the function f to each character of the string passed as argument, passing its index as the first argument. Each character is passed by address to ’f’ so it can be modified if necessary.
ft_putchar_fd -- Outputs the character ’c’ to the specified file descriptor.
ft_putstr_fd -- Outputs the string ’s’ to the specified file descriptor.
ft_putendl_fd -- Outputs the string ’s’ to the specified file descriptor followed by a newline.
ft_putnbr_fd -- Outputs the integer ’n’ to the specified file descriptor.
ft_split -- Allocates memory and returns an array of strings obtained by splitting ’s’ using the character ’c’ as a delimiter. Each string in the returned array (NULL terminated) is allocated independently.

Part3 functions

ft_lstnew -- Allocates memory (using malloc(3)) and returns a new node.
ft_lstadd_front -- Adds the node ’new’ at the beginning of the list.
ft_lstsize -- Counts the number of nodes in list.
ft_lstlast -- Finds the last node in list.
ft_lstadd_back -- Adds a new node at the end of list.
ft_lstdelone -- Deletes given one node in the list. Frees its content using the function ’del’ but free the node itself not free the next node.
ft_lstclear -- Deletes and frees the given node and all its successors, using the function ’del’ and free. Finally, set the pointer to the list to NULL.
ft_lstiter -- Iterates the list of each node's content with function f.
ft_lstmap -- Iterates the list of each node's content with function f, and return a new list with successive applications. The ’del’ function is used to delete the content of a node if needed.

Instructions

  • Compile the libft: run this command in terminal

     make
    
  • Use libft: include it in your header

     #include "libft.h"
    

Resources

It is important to understand C from basics. For the very basic concepts, Harvard CS 50 is a useful resources. W3School C language tutorial also provides interactive tutorial to help beginners to build up basic concepts.

AI usage

I use AI to help study and understand basic concepts. Here are the list of prompts I used before.
AI tool: Claude.ai (sonnet 4.6)
I create a project Computer Science Learning for Beginners.
The instruction of this project is:

Use simple and clear language to explain concepts for a beginner. Never give direct answer but guide the logic of the question.

I use AI to undestand some basic concepts:

  • bytes, why different data types has different bytes
  • ASCII characters to integer convertion
  • string length, size, buffer and memory in C
  • what is file descriptor
  • linked list structure
  • syntax of referencing and dereferencing pointer in C

Also comparison

  • functions' behaviour comparison. Like memcpy, strlcpy, strncpy, memmove
  • compare my functions' behaviour with built in functions and other peers' functions

articles

Compilation process with different files
Header Files in C
Compiling a C Program: Behind the Scenes

tutorials

W3School C language tutorial
Makefile tutorial by examples
Geeksgorgeeks linked list tutorial

About

Create a library including useful functions in the future projects and help student to understand from the basics of C language.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages