debut ecriture main part2

This commit is contained in:
hugodu69
2019-12-12 01:19:03 +01:00
parent ca5eb2a3dd
commit dc4502f577
2 changed files with 80 additions and 60 deletions

View File

@@ -2,66 +2,66 @@
** return an array of string with each word found in str, with c as separator
*/
/*
** #include <stdio.h>
** #include <stdlib.h>
** #include <unistd.h>
**
** size_t ft_strlen(const char *str)
** {
** size_t i;
**
** i = 0;
** while (str[i])
** i++;
** return (i);
** }
**
** char *ft_substr(char const *s, unsigned int start, size_t len)
** {
** char *str;
** size_t i;
**
** if (!s)
** return (NULL);
** if (ft_strlen(s) < start)
** return ("");
** if (!(str = (char *)malloc(sizeof(char) * (len + 1))))
** return (NULL);
** i = 0;
** while (i < len && s[start])
** str[i++] = s[start++];
** str[i] = '\0';
** return (str);
** }
**
** char **ft_split(char const *s, char c);
** char **ft_strsplit(char const *s, char c);
**
** int main(void)
** {
** char **str;
** int i;
**
** char *s;
** char c;
**
** i = -1;
** s = "svh ile ifh oiuo";
** c = ' ';
** str = ft_split(s, c);
** if (str)
** {
** printf("s : '%s'\n", s);
** printf("*str : '%p'\n", str[0]);
** while (str[++i])
** printf("str[%i] : '%s'\n", i, str[i]);
** }
** return (0);
** }
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
size_t ft_strlen(const char *str)
{
size_t i;
i = 0;
while (str[i])
i++;
return (i);
}
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *str;
size_t i;
if (!s)
return (NULL);
if (ft_strlen(s) < start)
return ("");
if (!(str = (char *)malloc(sizeof(char) * (len + 1))))
return (NULL);
i = 0;
while (i < len && s[start])
str[i++] = s[start++];
str[i] = '\0';
return (str);
}
char **ft_split(char const *s, char c);
char **ft_strsplit(char const *s, char c);
int main(void)
{
char **str;
int i;
char *s;
char c;
i = -1;
s = "svh ile ifh oiuo";
c = ' ';
str = ft_split(s, c);
if (str)
{
printf("s : '%s'\n", s);
printf("*str : '%p'\n", str[0]);
while (str[++i])
printf("str[%i] : '%s'\n", i, str[i]);
}
return (0);
}
//#include "libft.h"
#include "libft.h"
static int count(char const *s, char c)
{
@@ -82,7 +82,6 @@ void *ft_free(char **array, int w)
int i;
i = 0;
while (1);
while (array[i] != NULL && i < w)
free(array[i++]);
free(array);