mirror of
https://github.com/LucasCodeur/alcu.git
synced 2026-04-28 17:44:34 +02:00
working check_input
This commit is contained in:
+17
-79
@@ -14,88 +14,26 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../inc/get_next_line.h"
|
||||
#include "../libft/libft.h"
|
||||
#include "get_next_line.h"
|
||||
|
||||
// char *str_append(char *str, char *to_append) {
|
||||
// char *new_str;
|
||||
// int i;
|
||||
// int j;
|
||||
//
|
||||
// if (!str)
|
||||
// return to_append;
|
||||
// new_str = malloc(sizeof(char) * (ft_strlen(str) + ft_strlen(to_append) + 1));
|
||||
// if (!new_str)
|
||||
// return NULL;
|
||||
// i = -1;
|
||||
// while (str[++i])
|
||||
// new_str[i] = str[i];
|
||||
// j = -1;
|
||||
// while (to_append[++j])
|
||||
// new_str[i + j] = to_append[j];
|
||||
// new_str[i + j] = '\0';
|
||||
// free(str);
|
||||
// return (new_str);
|
||||
// }
|
||||
//
|
||||
// char *read_file(int fd) {
|
||||
// char *buf;
|
||||
// int char_readed;
|
||||
// char *content;
|
||||
//
|
||||
// content = NULL;
|
||||
// buf = malloc(sizeof(char) * 2);
|
||||
// if (!buf)
|
||||
// return (NULL);
|
||||
// buf[1] = '\0';
|
||||
// char_readed = read(fd, buf, 1);
|
||||
// while (char_readed > 0) {
|
||||
// str_append(content, buf);
|
||||
// char_readed = read(fd, buf, 1);
|
||||
// }
|
||||
// free(buf);
|
||||
// return (content);
|
||||
// }
|
||||
//
|
||||
|
||||
void free_split(char **tab) {
|
||||
int check_input(int fd) {
|
||||
int i;
|
||||
int j;
|
||||
char *line = NULL;
|
||||
|
||||
i = 0;
|
||||
while (tab[i]) {
|
||||
free(tab[i]);
|
||||
i++;
|
||||
line = get_next_line(fd);
|
||||
j = 0;
|
||||
while (line != NULL) {
|
||||
i = -1;
|
||||
while (line[++i])
|
||||
if (!(line[i] >= '0' && line[i] <= '9') && line[i] != '\n')
|
||||
return (free(line), -1);
|
||||
if (ft_atoi(line) < 1 || ft_atoi(line) > 10000)
|
||||
return (free(line), -1);
|
||||
free(line);
|
||||
j++;
|
||||
line = get_next_line(fd);
|
||||
}
|
||||
free(tab);
|
||||
}
|
||||
|
||||
int check_input(int fd)
|
||||
{
|
||||
char **content;
|
||||
int i;
|
||||
int j;
|
||||
char * line = NULL;
|
||||
line = get_next_line(fd);
|
||||
while (line != NULL)
|
||||
{
|
||||
|
||||
}
|
||||
content = ft_split(get_next_line(fd), '\n');
|
||||
if (!content)
|
||||
return (-2);
|
||||
i = -1;
|
||||
while (content[++i])
|
||||
{
|
||||
j = -1;
|
||||
while (content[i][++j])
|
||||
{
|
||||
if (content[i][j] <= '0' && content[i][j] >= '9')
|
||||
{
|
||||
free_split(content);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
free_split(content);
|
||||
return (i);
|
||||
return (j);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user