Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- int ft_count(char *str)
- {
- int i;
- int nb_word;
- i = 0;
- nb_word = 0;
- while (str[i])
- {
- if (str[i] && !(str[i] == ' ' || str[i] == '\t' || str[i] == '\n'))
- {
- nb_word++;
- while (str[i] && !(str[i] == ' ' || str[i] == '\t' || str[i] == '\n'))
- i++;
- }
- else
- i++;
- }
- return (nb_word);
- }
- int ft_wordlen(char *str)
- {
- int i;
- i = 0;
- while (str[i] && !(str[i] == ' ' || str[i] == '\t' || str[i] == '\n'))
- i++;
- return (i);
- }
- char **ft_split_whitespaces(char *str)
- {
- int nb_word;
- int i;
- char **dest;
- int k;
- int j;
- i = 0;
- j = 0;
- k = 0;
- nb_word = ft_count(str);
- printf("%i", nb_word);
- dest = (char**)malloc(sizeof(char*) * (nb_word + 1));
- dest[nb_word] = 0;
- while (dest[k] != 0)
- {
- if (str[i] && !(str[i] == ' ' || str[i] == '\t' || str[i] == '\n'))
- {
- dest[k] = (char*)malloc(sizeof(char) * (ft_wordlen(&str[i]) + 1));
- j = 0;
- printf("-%i-", i);
- while (str[i] && !(str[i] == ' ' || str[i] == '\t' || str[i] == '\n'))
- {
- dest[k][j] = str[i];
- i++;
- j++;
- }
- dest[k][j] = '\0';
- k++;
- }
- else
- i++;
- }
- return (dest);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement