Skip to content

Commit

Permalink
Bad ft_substr design fixed, bonus relink fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
FranciscoJesusGata committed Oct 20, 2021
1 parent 8121ffd commit e44eeab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
13 changes: 6 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# By: fgata-va <fgata-va@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/11/21 17:33:16 by fgata-va #+# #+# #
# Updated: 2021/03/18 21:56:12 by fgata-va ### ########.fr #
# Updated: 2021/10/20 18:01:30 by fgata-va ### ########.fr #
# #
# **************************************************************************** #

Expand All @@ -30,21 +30,20 @@ ft_printf/ft_pointers.c ft_printf/ft_unsigned.c

PRINTOBJS = $(PRINTSRC:.c=.o)

BONUSOBJS = $(BONUSSRC:.c=.o)
BONUSOBJS = $(patsubst ft_printf/%,ft_printf/%,$(BONUSSRC:.c=.o))

OBJS = $(SRC:.c=.o)

NAME = libft.a

all: $(NAME)

$(NAME): $(PRINTOBJS)
$(NAME): $(OBJS) $(PRINTOBJS)
$(CC) $(CFLAGS) -c -Ift_printf/ $(SRC)
ar rc $(NAME) $(OBJS) $(PRINTOBJS)
ar rc $(NAME) $(OBJS) $(O_OBJS) $(PRINTOBJS)

bonus: $(PRINTOBJS)
$(CC) $(CFLAGS) -c -I. -g $(BONUSSRC) $(SRC)
ar rc $(NAME) $(OBJS) $(BONUSOBJS) $(PRINTOBJS)
bonus: $(BONUSOBJS)
$(MAKE) O_OBJS="$(BONUSOBJS)" all

clean:
rm -f $(OBJS)
Expand Down
24 changes: 13 additions & 11 deletions ft_substr.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,37 @@
/* By: fgata-va <fgata-va@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/14 13:24:48 by fgata-va #+# #+# */
/* Updated: 2021/03/04 19:13:08 by fgata-va ### ########.fr */
/* Updated: 2021/10/20 17:35:23 by fgata-va ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *subst;
size_t maxl;
char *substr;
size_t total_len;
size_t i;
size_t j;
size_t sub_len;

if (!s)
return (NULL);
maxl = ft_strlen(s);
if (start >= maxl)
total_len = ft_strlen(s);
if (start >= total_len)
return (ft_strdup(""));
subst = (char *)malloc(sizeof(char) * len + 1);
if (!subst)
substr = (char *)malloc(sizeof(char) * len + 1);
if (!substr)
return (NULL);
i = start;
j = 0;
while (j < len && s[i] != '\0')
sub_len = len - start;
while (j < sub_len && s[i] != '\0')
{
subst[j] = s[i];
substr[j] = s[i];
j++;
i++;
}
subst[j] = '\0';
return (subst);
substr[j] = '\0';
return (substr);
}

0 comments on commit e44eeab

Please sign in to comment.