-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated functions with new and improved skills => CHECK
- Loading branch information
Anaelle LECLABART
committed
Apr 3, 2019
1 parent
91f95de
commit b85f371
Showing
44 changed files
with
401 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_fgetc.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: anleclab <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2019/01/23 14:37:34 by anleclab #+# #+# */ | ||
/* Updated: 2019/04/03 21:10:10 by anleclab ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
/* | ||
** Returns the next character of the file associated to the stream, or -1 if | ||
** the stream doesn't exist, the read fails, or the EOF has been reached. | ||
** Increments the iterator of the stream. | ||
*/ | ||
int ft_fgetc(t_file *stream) | ||
{ | ||
int rval; | ||
|
||
if (!stream) | ||
return (-1); | ||
if (!stream->buf[i]) | ||
{ | ||
stream->i = 0; | ||
if ((rval = read(stream->fd, stream->buf, BUFF_SIZE)) <= 0) | ||
{ | ||
stream->buf[0] = 0; | ||
return (-1); | ||
} | ||
stream->buf[rval] = 0; | ||
} | ||
return((int)stream->buf[stream->i++]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
# By: anaiel <[email protected]> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# Created: 2018/11/06 17:19:55 by anleclab #+# #+# # | ||
# Updated: 2019/04/03 20:29:51 by anleclab ### ########.fr # | ||
# Updated: 2019/04/03 22:13:46 by anleclab ### ########.fr # | ||
# # | ||
# **************************************************************************** # | ||
|
||
|
@@ -38,6 +38,7 @@ SRC_NAMES = ft_memset.c \ | |
ft_strncmp.c \ | ||
ft_atoi.c \ | ||
ft_isalpha.c \ | ||
ft_iswhitespace.c \ | ||
ft_isdigit.c \ | ||
ft_isalnum.c \ | ||
ft_isascii.c \ | ||
|
@@ -74,6 +75,8 @@ SRC_NAMES = ft_memset.c \ | |
ft_lstadd.c \ | ||
ft_lstiter.c \ | ||
ft_lstmap.c \ | ||
ft_lstcpy.c \ | ||
ft_lstappend.c \ | ||
ft_strsplitlst.c \ | ||
ft_putstrarray.c \ | ||
ft_putstrlst.c \ | ||
|
@@ -85,8 +88,6 @@ SRC_NAMES = ft_memset.c \ | |
ft_double_power.c \ | ||
ft_array_swap.c \ | ||
ft_itoa_base.c \ | ||
ft_litoa.c \ | ||
ft_llitoa.c \ | ||
ft_ldouble_power.c \ | ||
ft_tabdel.c \ | ||
ft_fopen.c \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: anaiel <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/11/06 17:19:32 by anleclab #+# #+# */ | ||
/* Updated: 2019/04/03 20:25:37 by anleclab ### ########.fr */ | ||
/* Updated: 2019/04/03 22:13:21 by anleclab ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -21,6 +21,9 @@ | |
|
||
# define BUFF_SIZE 4096 | ||
|
||
# define LLONG_MAX 9223372036854775807 | ||
# define INT_MIN -2147483647 | ||
|
||
typedef struct s_list | ||
{ | ||
void *content; | ||
|
@@ -37,6 +40,7 @@ typedef struct s_file | |
|
||
int ft_isalpha(int c); | ||
int ft_isdigit(int c); | ||
int ft_iswhitespace(int c); | ||
int ft_isalnum(int c); | ||
int ft_isascii(int c); | ||
int ft_isprint(int c); | ||
|
@@ -94,6 +98,8 @@ void ft_lstdel(t_list **alst, void (*del)(void *, size_t)); | |
void ft_lstadd(t_list **alst, t_list *new); | ||
void ft_lstiter(t_list *lst, void (*f)(t_list *elem)); | ||
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)); | ||
t_list *ft_lstcpy(t_list *lst); | ||
t_list *ft_lstappend(t_list **lst, t_list *link); | ||
t_list *ft_strsplitlst(char *s, char c); | ||
void ft_putstrarray(const char **str); | ||
void ft_putstrlst(t_list *lst); | ||
|
@@ -105,12 +111,10 @@ unsigned char *ft_wchar_to_bytes(wint_t c); | |
double ft_double_power(double n, int pow); | ||
void ft_array_swap(int *array, int i1, int i2); | ||
char *ft_itoa_base(int n, int base); | ||
char *ft_litoa(long int nb); | ||
char *ft_llitoa(long long int nb); | ||
long double ft_ldouble_power(long double n, int pow); | ||
void ft_tabdel(char **tab); | ||
t_file *ft_fopen(const char *path); | ||
int ft_fclose(t_file *stream); | ||
int ft_fclose(t_file **stream); | ||
int ft_fgetc(t_file *stream); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,14 +6,21 @@ | |
/* By: anleclab <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2019/01/02 10:35:50 by anleclab #+# #+# */ | ||
/* Updated: 2019/01/23 14:08:41 by anleclab ### ########.fr */ | ||
/* Updated: 2019/04/03 20:37:43 by anleclab ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
/* | ||
** Swaps elements at index i1 and i2 if array exists. | ||
*/ | ||
void ft_array_swap(int *array, int i1, int i2) | ||
{ | ||
int tmp; | ||
|
||
if (!array) | ||
return ; | ||
tmp = array[i1]; | ||
array[i1] = array[i2]; | ||
array[i2] = tmp; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,44 +6,41 @@ | |
/* By: anleclab <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/11/09 13:51:13 by anleclab #+# #+# */ | ||
/* Updated: 2019/01/23 14:08:43 by anleclab ### ########.fr */ | ||
/* Updated: 2019/04/03 20:54:03 by anleclab ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
static int al_isspace(const char c) | ||
{ | ||
if (c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r' | ||
|| c == ' ') | ||
return (1); | ||
else | ||
return (0); | ||
} | ||
|
||
/* | ||
** Returns the int form of the number in the string, or 0 if the string is not | ||
** a number. | ||
** Ignores starting spaces and ending characters which are not digits. | ||
*/ | ||
int ft_atoi(const char *s) | ||
{ | ||
unsigned long long res; | ||
int i; | ||
int sign; | ||
|
||
i = 0; | ||
if (!s) | ||
return (0); | ||
res = 0; | ||
sign = 1; | ||
while (s[i] && al_isspace(s[i])) | ||
i++; | ||
if (s[i] == '+' || s[i] == '-') | ||
while (*s && ft_iswhitespace(*s)) | ||
s++; | ||
if (*s == '+' || *s == '-') | ||
s++; | ||
else if (*s == '-') | ||
{ | ||
if (s[i] == '-') | ||
sign = -1; | ||
i++; | ||
sign = -1; | ||
s++; | ||
} | ||
while (s[i] && ft_isdigit(s[i])) | ||
while (*s && ft_isdigit(*s)) | ||
{ | ||
res = res * 10 + s[i] - '0'; | ||
if (res > 9223372036854775807) | ||
return ((sign > 0 ? -1 : 0)); | ||
i++; | ||
res = res * 10 + *s - '0'; | ||
if (res > LLONG_MAX) | ||
return ((sign > 0) ? -1 : 0); | ||
s++; | ||
} | ||
return ((int)(res * sign)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,15 @@ | |
/* By: anleclab <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/11/09 18:22:55 by anleclab #+# #+# */ | ||
/* Updated: 2019/01/23 14:08:44 by anleclab ### ########.fr */ | ||
/* Updated: 2019/04/03 20:55:50 by anleclab ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
/* | ||
** Sets n bits to 0. | ||
*/ | ||
void ft_bzero(void *s, size_t n) | ||
{ | ||
ft_memset(s, 0, n); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,15 @@ | |
/* By: anleclab <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/12/12 14:54:14 by anleclab #+# #+# */ | ||
/* Updated: 2019/01/23 14:08:46 by anleclab ### ########.fr */ | ||
/* Updated: 2019/04/03 20:57:53 by anleclab ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
/* | ||
** Returns n to the power of pow where n is a double and pow a signed int. | ||
*/ | ||
double ft_double_power(double n, int pow) | ||
{ | ||
if (pow == 0) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,18 +6,22 @@ | |
/* By: anleclab <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2019/01/23 15:14:07 by anleclab #+# #+# */ | ||
/* Updated: 2019/01/23 15:22:56 by anleclab ### ########.fr */ | ||
/* Updated: 2019/04/03 21:20:23 by anleclab ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
int ft_fclose(t_file *stream) | ||
/* | ||
** Closes the file descriptor and frees the buffer contained in the stream. | ||
*/ | ||
int ft_fclose(t_file **stream) | ||
{ | ||
if (!stream) | ||
if (!stream || !*stream) | ||
return (0); | ||
if (close(stream->fd) == -1) | ||
if (close((*stream)->fd) == -1) | ||
return (-1); | ||
free(stream->buf); | ||
free(*stream); | ||
stream = NULL; | ||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,29 +6,32 @@ | |
/* By: anleclab <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2019/01/23 14:37:34 by anleclab #+# #+# */ | ||
/* Updated: 2019/01/23 15:42:22 by anleclab ### ########.fr */ | ||
/* Updated: 2019/04/03 22:34:00 by anleclab ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
/* | ||
** Returns the next character of the file associated to the stream, or -1 if | ||
** the stream doesn't exist, the read fails, or the EOF has been reached. | ||
** Increments the iterator of the stream. | ||
*/ | ||
int ft_fgetc(t_file *stream) | ||
{ | ||
int ret; | ||
unsigned char res; | ||
int rval; | ||
|
||
if (!stream) | ||
return (-1); | ||
if (!(stream->buf[0])) | ||
if (!stream->buf[i]) | ||
{ | ||
if ((ret = read(stream->fd, stream->buf, BUFF_SIZE)) <= 0) | ||
stream->i = 0; | ||
if ((rval = read(stream->fd, stream->buf, BUFF_SIZE)) <= 0) | ||
{ | ||
stream->buf[0] = 0; | ||
return (-1); | ||
} | ||
stream->buf[ret] = 0; | ||
stream->i = 0; | ||
stream->buf[rval] = 0; | ||
} | ||
res = stream->buf[stream->i++]; | ||
return((int)res); | ||
return((int)stream->buf[stream->i++]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,32 +6,32 @@ | |
/* By: anleclab <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/11/19 09:18:47 by anleclab #+# #+# */ | ||
/* Updated: 2019/01/23 14:08:47 by anleclab ### ########.fr */ | ||
/* Updated: 2019/04/03 21:16:26 by anleclab ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
/* | ||
** Returns the number of line of the file. | ||
*/ | ||
int ft_filelinecount(int fd) | ||
{ | ||
int nblines; | ||
int readchar; | ||
char buf[51]; | ||
int rval; | ||
char buf[BUFF_SIZE + 1]; | ||
int i; | ||
|
||
buf[50] = 0; | ||
readchar = read(fd, buf, 50); | ||
nblines = (readchar > 0 ? 1 : 0); | ||
while (readchar > 0) | ||
if ((rval = read(fd, buf, BUFF_SIZE)) <= 0) | ||
return (0); | ||
buf[rval] = 0; | ||
nblines = 1; | ||
while (rval > 0) | ||
{ | ||
i = 0; | ||
while (i < 50) | ||
{ | ||
if (buf[i] == '\n') | ||
nblines++; | ||
i++; | ||
} | ||
readchar = read(fd, buf, 50); | ||
i = -1; | ||
while (buf[++i]) | ||
nblines += (buf[i] == '\n'); | ||
rval = read(fd, buf, BUFF_SIZE); | ||
} | ||
return (nblines); | ||
} |
Oops, something went wrong.