A commented version of my libft, with details about how my algorithms work and simple main functions to compile them.

Overview

LIBFT COMMENTED VERSION :


πŸ”§ PART I :



πŸ“– FT_STRCHR :


πŸ”§ PART II :



πŸ“– FT_SUBSTR :



/*
 * DEFINITION :
 * CREATES A SUBSTRING FROM A STRING WITH PREDETERMINED POSITION AND SIZE.
 *
 * PROTOTYPE :
 * char *ft_substr(char const *s, unsigned int start, size_t len);
 *
 * PARAMETERS :
 * *S : THE SUBSTRING FROM WHICH WE CREATE THE SUBSTRING.
 * INDEX : STARTING POSITION OF THE SUBSTRING.
 * LEN : SIZE OF THE SUBSTRING.
 *
 * IMPLEMENTATION :
 * . FIRST WE CREATE A STRING TO RETURN AT THE END.
 * . WE CHECK IF S IS NULL, PROTECTION FROM NULL ENTERED BY USER.
 * . THEN WE TAKE THE SIZE OF S, IF ITS SIZE IS SMALLER THAN THE START, 
 * WE RETURN AN EMPTY STRING.
 * . TO PERFORM A SAFE MEMORY ALLOCATION, IF THE LENGTH OF S IS SMALLER THAN
 * LEN, WE WILL CHANGE THE SIZE OF LEN, MAKING IT THE SIZE OF S.
 * . ALLOCATE MEMORY FOR OUR NEW STRING.
 * . COPY THE STRING TO OUR NEW STRING SUBSTR.
 * . RETURN OUR NEW SUBSTRING.
 *
 * ET VOILAAA !
*/

#include <stdio.h>
#include <stdlib.h>

/*CALCULATE THE LENGTH OF A STRING*/

size_t	ft_strlen(const char *s)
{
	size_t	len;

	len = 0;
	while (*s++)
		len++;
	return (len);
}

/*DUPLICATE STRING*/

char	*ft_strdup(const char *s)
{
	char	*dest;

	if (s == NULL) /*PROTECTION FROM NULL INPUT [SEGFAULT]*/
		return (NULL);
	dest = (char *) malloc(sizeof(char) * (ft_strlen(s) + 1));
	if (dest == NULL) /*MALLOC PROTECTION*/
		return (NULL);
	while (*s) /*WHILE S CONTAINS CHARACTERS COPY CONTENT TO DEST*/
		*dest++ = *s++;
	*dest = '\0'; /*APPEND A '\0' TO THE END OF THE STRING*/
	return (dest);
}

/*COPY A STRING TO ANOTHER WITH A SPECIFIC SIZE*/

size_t	ft_strlcpy(char *dest, const char *src, size_t size)
{
	size_t	i;

	if (!dest || !src)
		return (0);
	i = 0;
	if (size != 0)
	{
		/*AS LONG AS SIZE IS DIFFERENT FROM ZERO AND OUR SRC CONTAINS CHARACTERS
		*WE WILL COPY EACH CHARACTER FROM SRC TO dest
		*/
		while (src[i] != '\0' && i < (size - 1))
		{
			dest[i] = src[i];
			i++;
		}
		dest[i] = '\0';
	}
	return (ft_strlen(src));
}

char	*ft_substr(const char *s, unsigned int start, size_t len)
{
	char	*substr; /*CREATE THE SUBSTRING*/

	if (s == NULL) /*PROTECTION FROM NULL*/
		return (NULL);
	/*IF OUR STARTING POSITION IS BEYOND OR AT THE END OF THE STRING WE return
	*EN EMPTY STRING
	**/
	if (start >= ft_strlen(s))
		return (ft_strdup(""));
	/*TO PERFORM A SAFE MEMORY ALLOCATION, IF THE LENGTH OF S IS SMALLER THAN LEN
	*WE WILL UPDATE THE SIZE OF LEN, MAKING IT EQUAL TO THE SIZE OF OUR STRING S.
	*/
	if (ft_strlen(s) < len)
		len = ft_strlen(s);
	/*ALLOCATE MEMORY FOR OUR NEW STRING*/
	substr = (char *) malloc (sizeof(char) * (len + 1));
	/*MALLOC PROTECTION*/
	if (substr == NULL)
		return (NULL);
	/*COPY THE STRING S TO OUR NEW STRING*/
	ft_strlcpy(substr, s + start, len + 1);
	return (substr);
}

int	main(int argc, char **argv)
{
	(void)	argc;
	(void)	argv;
	printf("%s\n", ft_substr("1337 BENGUERIR", 5, 12));
	return (EXIT_SUCCESS);
}

πŸ“– FT_STRJOIN :



#include <stdio.h>
#include <stdlib.h>

/* DEFINITION :
 * A FUNCTION THAT CONCATENATES S2 TO S1 AND RETURNS THE CONCATENATED STRING.
 *
 * PROTOTYPE :
 * char	*ft_strjoin(const char *s1, const char *s2);
 *
 * PATAMETERS :
 * S1 : DESTIONATION STRING TO CONCATENATE S2 (SOURCE) AT THE END OF IT.
 * S2 : SOURCE STRING TO BE CONCATENATED.
 *
 * IMPLEMENTATION :
 * . FIRST WE DECLARE OUR STRING TO HOLD THE CONCATENATION IN.
 * . WE ALLOCATE THE TOTAL SIZE USING FT_STRLEN OF S1 AND S2 ADDING TO THAT
 * ONE CHARACTER FOR THE NULL TERMINATION.
 * . WE PROTECT OUR MALLOC (IF NOT ENOUGH MEMORY IN THE SYSTEM, MALLOC FAILS.).
 * . THEN WE PERFORM A FIRST LOOP STARTING BOTH INDEXES FROM ZERO.
 * . WE RESET ONE OF THE INDEXES SO WE COPY THE SOURCE STRING FROM WHERE THE 
 * OTHER INDEX STOPPED.
 * . WE CONCATENATE SOURCE WHERE THE OTHE OTHER INDEX STOPPED, SO THE OTHER INDEX 
 * INDECATES THE TOTAL CONCATENATION.
 * . WE RETURN THE CONCATENATED STRING.
 *
*/

/*FUNCTION TO CALCULATE THE lENGTH OF A STRING*/

size_t	ft_strlen(const char *s)
{
	size_t	len;

	len = 0;
	while (*s++)
		len++;
	return (len);
}

/*FUNCTION TO CONCATENATE TWO STRINGS*/

char	*ft_strjoin_commented(char const *s1, char const *s2)
{
	char	*joined; /*CONTANATED STRING TO BE RETURNED*/
	size_t	i;
	size_t	j;

	i = 0;
	j = 0;
	/*ALLOCATE THE TOTAL SIZE OF CONCATENATION USING STRLEN + ADDING A CHAR 
	 * FOR NULL TERMINATION*/
	joined = (char *) malloc (sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1));
	/*MALLOC PROTECTION, IF IT FAILS*/
	if (!joined)
		return (NULL);
	/*COPYING DESTINATION STRING TO OUR STRING JOINED*/
	while (s1[j] != '\0')
	{
		joined[i] = s1[j];
		i++;
		j++;
	}
	/*RESETING J SO WE USE IT FOR CONCATENATION*/
	j = 0;
	/*CONCATENATING SOURCE STRING AT THE END OF SOURCE*/
	while (s2[j] != '\0')
	{
		joined[i] = s2[j];
		i++;
		j++;
	}
	/*NULL TERMINATING OUR JOINED STRING*/
	joined[i] = '\0';
	/*RETURNING OUR STRING JOINED*/
	return (joined);
}

int	main(int argc, char **argv)
{
	(void)	argc;
	(void)	argv;
	printf("%s\n", ft_strjoin_commented("1337 ", "Benguerir"));
	return (EXIT_SUCCESS);
}

πŸ“– FT_STRTRIM :






Owner
Abdessamad Laamimi
ZERO-DAY
Abdessamad Laamimi
Well-organized, commented and documented sample project that shows the basic functionalities of the 42's mlx library.

miniLibX sample | slucas-s I developed this sample project to play around with the basic functionalities of the miniLibX, the simple graphics library

S. Lucas Serrano 37 Jun 28, 2022
Make CVE-2020-0668 exploit work for version < win10 v1903 and version >= win10 v1903

CVE-2020-0668 Made CVE-2020-0668 exploit work for version < win10 v1903 and version >= win10 v1903 Diaghub Exploit (< v1903) powershell exploit works

null 13 Dec 15, 2021
This is a OOSDK port of flat's ps4_remote_pkg_installer, all credit goes to them and their amazing work!

ps4_remote_pkg_installer-OOSDK This is a OOSDK port of flat's ps4_remote_pkg_installer, all credit goes to them and their amazing work! NOTES Some fun

null 24 Jun 24, 2022
Collaborative and comprehensive testing for libft project

first Draft Collaborate on libft tests, everything here is open to suggestions This is hopefully a way to both practice git collaboration and creat a

null 4 Nov 24, 2021
A Tester for the Libft 42 project based off Tripouille

libfttester A Tester for the Libft 42 project This Tester was made by NotJustJoe, using Tripouille Leaks checker and kind of inspired off his work (ht

trofidal 7 May 20, 2022
A console application using CPP that manages the guest details and check in and quarantine period of individual

A console application using CPP that manages the guest details and check in and quarantine period of individual(14 days). Efficient searching of guest, sorting and availability of room details can be found using the applications.

KAZI SAHARIAR RAHI 2 Nov 24, 2021
A modern-day Boss Key software tool. Switch instantly from work to play & play to work with Bosky.

Bosky By: Seanpm2001, Bosky-dev Et; Al. Top README.md Read this article in a different language Sorted by: A-Z Sorting options unavailable ( af Afrika

Sean P. Myrick V19.1.7.2 1 Nov 11, 2021
Bank Management System is based on a concept of recording customer’s account details

Bank Management System is based on a concept of recording customer’s account details. Here the user can perform all the tasks like creating an account, deposit amount, withdraw amount, check balance, view all account holders detail, close an account and modify an account. There’s no login system for this project. All the main features for banking system are set in this project.

AmrMohamed 2 Feb 12, 2022
null 239 Jul 6, 2022
PRINT++ is a simple, open source print library for C++, the main usage of PRINT++ is printing out "log" messages

note that for now, print++ is using std::cout. In future it will be using own print function. Windows version can be unstable That library is in alpha

Ksawery 3 Jan 23, 2022
Original hVNC has been recoded to work with all version of windows above XP. Thanks to the original author for this wonderful tool.

hVNC - Recoded This is the recoded version of the hVNC found in TinyNuke trojan. Compiling Compile tested with Visual Studio 2017. No compile errors.

Snow Leopard 8 Jan 22, 2022
A run-time C++ library for working with units of measurement and conversions between them and with string representations of units and measurements

Units What's new Some of the CMake target names have changed in the latest release, please update builds appropriately Documentation A library that pr

Lawrence Livermore National Laboratory 103 Jun 24, 2022
EarlyBird process hollowing technique (BOF) - Spawns a process in a suspended state, inject shellcode, hijack main thread with APC, and execute shellcode

HOLLOW - Cobalt Strike BOF Authors: Bobby Cooke (@0xBoku) Justin Hamilton (@JTHam0) Octavio Paguaga (@OakTree__) Matt Kingstone (@n00bRage) Beacon Obj

Bobby Cooke 188 Jun 27, 2022
An operating system. Its main goal? Readable code, developer experience and documentation.

OS Dependencies Required for development. sudo apt install build-essential nasm grub-pc-bin grub-common xorriso Required for building cross-compiler.

Stijn Rogiest 2 Jun 20, 2022
GPS parser which read raw GPS messages, selects only the valid ones and sends them to CAN bus

EagleTRT GPS System for Fenice GPS parser which read raw GPS messages, selects only the valid ones and sends them to CAN bus Compiling GPS Logger gps_

E-Agle Trento Racing Team 1 Nov 11, 2021
Steals plaguecheat.cc login information and sends them over Discord webhook

PlagueStealer DO NOT USE THIS!!! I TAKE NO RESPONSIBILITY FOR ANY DAMAGE CAUSED How to use: Make a Discord webhook (watch this if you dont know how: h

Sinner 3 Dec 28, 2021
Creates 3D lithophanes from image files, exports them to stl files, ready for slicing and 3D printing.

LithoMaker Creates 3D lithophanes from PNG image files and exports them to STL files, ready for slicing and 3D printing. Download the latest release h

Lars Muldjord 13 Jun 29, 2022