Skip to content

berkeldemir/libft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

109 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

42-libft



Your first library. / Sizin yazacağınız ilk kütüphane.

score

**EN:** In this project of 42 Cursus, you will create your own library. And instead of creating them again and again in the future, you will be able to use them by basically adding libft to your project root.

TR: 42 Ana Müfredatın ilk projesi olan libft'de kendi kütüphanenizi oluşturacaksınız. Ve daha sonra yazacağınız projelerde, her bir fonksiyonu tek tek baştan yazmak yerine libft'yi projenize ekleyerek kolayca kullanabilir hale geleceksiniz.

---------------------

Installation / Kurulum

EN: You can directly download as a ZIP from up there by clicking green 'code' button.
TR: Yukarıdaki yeşil renkli 'code' bloğuna tıklayarak 'ZIP' formatında indirebilirsiniz.

Usage / Kullanım

After installing, you can run the app with the following command:

make fclean 
make
make clean

make fclean : first you need to remove if libft.a already created.
make : create ft_*.o (! ft_lst*.o) files and libft.a
make clean : remove *.o files, they've already added to libft.a

If you want to also run and check for bonuses:

make fclean
make
make bonus
make clean

make fclean : first you need to remove if libft.a already created.
make : create ft_.o (! ft_lst.o) files and libft.a
make bonus : create ft_lst*.o files and add to libft.a
make clean : remove *.o files, they've already added to libft.a

Features / Özellikler

File / Dosya Description Açıklama
ft_atoi Convert ASCII to Integer ASCII değerini bir integer'e çevir
ft_bzero Set n bytes to zero n baytı sıfır olarak ayarla
ft_calloc Basically malloc, but W/b_zero Aslınca malloc, b_zero ile
 ft_isalnum  Alphabetic or Numeric ? return 1  Alfabetik ya da numerik ise 1 döndür
ft_isalpha Alphabetic ? return 1 Alfabetik ise 1 döndür
ft_isascii ASCII Character ? return 1 ASCII karakter ise 1 döndür
ft_isdigit Numeric ? return 1 Numerik ise 1 döndür
 ft_isprint Printable ? return 1 Yazdırılabilir karakter ise 1 döndür
ft_itoa Convert Integer to String Integer değerinden String oluştur
(B) ft_lstaddback Put a node to end of the list Listenin sonuna bir node ekle
(B) ft_lstaddfront Put a node to beggining of the list Listenin başına bir node ekle
(B) ft_lstclear Clear any node from the list Listedeki bütün node'ları sil
(B) ft_lstdelone Remove a node in a list Listedeki bir node'u sil
(B) ft_lstiter Apply f funct any node (return new) Listedeki her node'a f uygula, yenisini döndür
(B) ft_lstlast Return a pointer to the last node Listedeki son node'un adresini döndür
(B) ft_lstmap Apply f funct any node (return same) Listedeki her node'a f uygula, eskisini döndür
(B) ft_lstnew Create a new node module Yeni bir node elementi oluştur
(B) ft_lstsize Return the size of list Listedeki node sayısını döndür
ft_memchr Search n bytes for c int the memory Hafızada n bayt boyunca 'c' karakterini ara
ft_memcmp Compare n bytes of *s1 and *s2 *s1 ve *s2 tan itibaren n baytı karşılaştır
ft_memcpy Copy n bytes from *src to *dst *src'den *dst'ye n bayt kopyala
ft_memmove Copy n bytes from *src to *dst (1) *src'den *dst'ye n bayt kopyala (1)
ft_memset Set len bytes of *b to c *b'den itibaren len byte'ı c olarak ayarla
ft_puthcar_fd Print given c to file descriptor (2) File descriptor'a (fd) c karakteri yazdır. (2)
ft_putendl_fd Print s string + \n to fd. File desc.'a (fd) s stringi + \n yazdır
ft_putnbr_fd Print given integer n to fd. Verilen n integerı'nı fd'ye yazdır
ft_putstr_fd Print given string s to fd.  Verilen s stringi'ni fd'ye yazdır
ft_split (3) (3)
ft_strchr Search for c int in s string s stringi'nde c integerı'nı ara
ft_strdup Duplicate given string and ret. new Verilen stringi kopyala ve yenisi döndür
ft_striteri Apply f to any char of str ret. same Her karaktere f fonk uygula, eskisini döndür
ft_strjoin Fuse two strings, return new İki stringi ucuca ekle, yenisini döndür
ft_strlcat Copy src right next to dst (4) src'yi dst'nin hemen sağına kopyala (4)
ft_strlcpy Copy size bytes of src to dest src'nin size bayt kadarını dest'e kopyala
 ft_strlen Return lengt of given string Verilen stringin uzunluğunu döndür
ft_strmapi Apply f to any char of str ret. new  Her karaktere f fonk uygula, yenisini döndür
ft_strncmp Compare n bytes of s1 and s2 strs s1 ve s2 stringlerinin n baytını karşılaştır
ft_strnstr Search for s2 in s1 for len bytes len bayt boyunca s1'in içinde s2 ara
ft_strrchr ft_strchr but return the last one ft_strchr ama bulunan son char'ı döndür
ft_strtrim (5)  (5)
ft_substr (6) (6)
ft_tolower Convert lowercase if it is upp. Büyük harf ise küçük harfe çevir
ft_toupper  Convert uppercase if it is lowc. Küçük harf ise büyük harfe çevir
libft.h Define all functs and t_list there Bütün fonksiyonları ve t_list'i tanımlayın
Makefile Easier way to create and archive Arşiv dosyası oluşturmanın kolay yolu

(B): Bonus Functions

(1): ft_memmove function works more tidious then ft_memcpy to do not loose any data. (Please check 'Hints' 1st)
(1): ft_memmove fonksiyonu ft_memcpy'ye kıyasla data kaybetmemek konusunda daha titiz çalışır. ('İpucuları' 1'i inceleyin)

(2): To learn more about File Descriptors (fd's) check out Hinst 2nd.
(2): File Descriptor'lar (fd'ler) hakkında daha fazla bilgi için İpucuları 2'yi inceleyin.

(3): Split the given string s whenever you see the 'c' character and return an array of strings you've splitted.
(3): Verilen string'i 'c' karakterlerinin olduğu yerlerden ayır ve bu ayırdığın stringlerden oluşan bir string dizisi döndür.

(4): dstsize must be given greater than strlen(src) otherwise original and also implementation of mine crushes as it should. And check 'man strlcat' to see return values.
(4): dstsize verilen src'den büyük uzunlukta olmalıdır, aksi taktirde orijinal fonksiyon ve uyarlamam olması gerektiği gibi çökecektir. Döndürülmesi gereken değerleri görmek için 'man strlcat' kullanın.

(5): It has two parameters, first one the string to trim and the other one: array of chars will be trimming. Returns a new string which is trimmed from start and end.
(5): İki parametre alır, ilki kırpılacak string, diğeri kırpılacak karakterler dizisi. Baştan ve sondan bu değerlerle kırpılmış yeni diziyi döndürür.

(6): It has three parameters, main string, start index, new length. Start from 'start' index and return a new string 'len + 1 (\0)' lenght.
(6): Üç parametre alır, ana string, başlangıç indexi, yeni uzunluk. 'start' indexinden başlayarak 'len + 1 (\0)' uzunluğunda yeni bir string döndürür.

Hints / İpucuları

1. ft_memmove VS ft_memcpy

E C  O L E _ 2 \0
0 1 2 3 4 5 6 7 8
^  
s1 s2  
char s1[] = "ECOLE_42";
char *s2 = &s1[3];
ft_memcpy(s2, s1, 5);

When we apply the code above, what we want to do?
We want to copy 'ECOLE' to where says 'LE_42'
Let's go step by step, first:
'E' is overwrited on &'L' -> 'ECOEE_42'
'C' -> &'E' -> "ECOEC_42"
'O' -> &'_' -> "ECOECO42"
'L' -> &'4' -> "ECO"... BUT WAIT 'L'?
It is not 'L' anymore we overwrite 'E' into L.
So yes, as you see we lost the value of 3rd index.
And result will be: "ECOECOEC"

What if we try it with ft_memmove?

char s1[] = "ECOLE_42";
char *s2 = &s1[3];
ft_memmove(s2, s1, 5);
E C  O L E _ 2 \0
0 1 2 3 4 5 6 7 8
^ ^ ^   ^
s1 s2 s1+len   s2+len

Because of dst is greater than src (which means dst comes after src in memory)
ft_memmove will do the following:
'E' is going to overwrited at where the '2' is -> '2'
'L' -> &'4' -> "ECOLE_LE"
'O' -> &'_' -> "ECOLEOLE"
'C' -> &'E' -> "ECOLCOLE"
'E' -> &'L' -> "ECOECOLE"
TA DAAAA!

2. File Descriptor (fd)

Guess we all remember about the write() function. Remember it prints some characters on terminal output, if you use it as *write(1, &, );* What does 1 means here? -> STDOUT (Standart Output, which means the terminal in usage.) What else it can get?
fd DESCRIPTION  
0 reading input from keyboard
1 writing normal output, to the terminal
2 writing error mesages to standart error
file any other file descriptor to write in file.
#include <fcntl.h>

int  main(void)
{
  int  fd;

  fd = open("file.txt", O_WRONLY | O_CREAT | O_TRUNC, 0777);
  if (fd == -1)
    return (1);
  write(fd, "Fascinating!", 12);
}
  • This code above looks for a file called file.txt in the current directory and;
  • if it does not exist, it creates it (O_CREAT) with 777 permissions,
  • then opens it only write mode (O_WRONLY),
  • any existing content in the file will be deleted (O_TRUNC),
  • and finally puts the text inside file.

All of the *_fd.c files in this project does the same basically, puts a string to the file. But of course it is on you to change it as anything you want, if you give 1 it will give output on stdout etc.

About

Create your own library!

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors