コード例 #1
0
ファイル: main_17.c プロジェクト: sakajo/workspace
int		main(int ac, char **av)
{
		t_list	*list1;
		t_list	*list2;
		char	**tab1;
		char	**tab2;

		if (ac == 3)
		{
				tab1 = ft_split_whitespaces(av[1]);
				tab2 = ft_split_whitespaces(av[2]);
				list1 = ft_list_push_params(tab_len(tab1), tab1);
				list2 = ft_list_push_params(tab_len(tab2), tab2);
				ft_list_sort(&list1, &ft_strcmp);
				ft_list_sort(&list2, &ft_strcmp);
				ft_putstr("List1:\n");
				ft_print_list(list1);
				ft_putstr("List2:\n");
				ft_print_list(list2);
				ft_putstr("List1 + List2:\n");
				ft_sorted_list_merge(&list1, list2, &ft_strcmp);
				ft_print_list(list1);
		}
		return (0);
}
コード例 #2
0
struct s_stock_par	*ft_param_to_tab(int ac, char **av)
{
	t_stock_par	*par;
	int			i;
	int			j;

	par = (t_stock_par*)malloc(sizeof(t_stock_par) * (ac + 1));
	i = 0;
	while (i < ac)
	{
		j = 0;
		while (av[i][j] != '\0')
			j++;
		par[i].size_param = j;
		par[i].str = av[i];
		par[i].copy = (char*)malloc(sizeof(char) * (j + 1));
		par[i].copy[j] = '\0';
		while (j > 0)
		{
			j--;
			par[i].copy[j] = av[i][j];
		}
		par[i].tab = ft_split_whitespaces(av[i]);
		i++;
	}
	par[i].str = 0;
	return (par);
}
コード例 #3
0
ファイル: client.c プロジェクト: francoios/Ft_P
int						core(int r, char *buff)
{
	char				**param;

	ft_putstr(C_NONE);
	ft_putstr(C_GREEN);
	buff[r] = '\0';
	param = ft_split_whitespaces(buff);
	send(g_sock, buff, ft_strlen(buff), 0);
	if (ft_strcmp(buff, "quit\n") == 0)
		return (1);
	ft_bzero(buff, 1024);
	if (param[0] && ft_strcmp("get", param[0]) == 0)
		file_get(param[1]);
	else if (param[0] && ft_strcmp("put", param[0]) == 0)
	{
		if (param[1] && param[2] == NULL)
			put_file(param[1]);
		else
			write(1, "ERROR -> Need a file name as second parameter\n", 46);
	}
	else
		get_data();
	print_prompt();
	return (0);
}
コード例 #4
0
ファイル: extract_opcode.c プロジェクト: magouin/Corewar
int			extract_opcode(char **line)
{
	char	**parts;
	int		i;
	int		nb_spaces;
	char	*op_name;
	char	*tmp;

	if (is_comment_or_empty(*line))
		return (0);
	tmp = *line;
	nb_spaces = count_spaces(*line);
	parts = ft_split_whitespaces(*line);
	op_name = ft_strdup(parts[0]);
	i = 0;
	while (parts[i])
		free(parts[i++]);
	free(parts);
	if (op_name != NULL)
	{
		return (get_code_value(op_name, line, tmp, nb_spaces));
	}
	else
		throw_error(1);
	return (0);
}
コード例 #5
0
ファイル: ft_param_to_tab.c プロジェクト: bndao/gnl
t_stock_par			*ft_param_to_tab(int ac, char **av)
{
	int				nb;
	int				cpt;
	t_stock_par		*tab;

	nb = 0;
	cpt = 0;
	if (!av)
		return (NULL);
	if (!(tab = (t_stock_par *)malloc(sizeof(t_stock_par) * ac + 1)))
		return (NULL);
	nb = 0;
	while (nb < ac)
	{
		ft_memset(&tab[nb], 0, sizeof(struct s_stock_par));
		tab[nb].size_param = ft_strlen(av[nb]);
		tab[nb].str = av[nb];
		tab[nb].copy = ft_strdup(av[nb]);
		tab[nb].tab = ft_split_whitespaces(av[nb]);
		nb++;
	}
	tab[nb].str = NULL;
	return (tab);
}
コード例 #6
0
int	main(void)
{
	char	c[]

	c = "split that 	f*****g white 	space";
	ft_split_whitespaces(c);
	return (0);
}
コード例 #7
0
ファイル: server.c プロジェクト: qmuntada/ft_p
int		ft_command(char *data, t_uenv *user, char *pwd)
{
	int			wt;
	char		**param;

	if (data[0] == '\0')
	{
		send(user->cs, "Wrong command\n", 14, 0);
		send(user->cs, "ERROR\n", 6, 0);
		return (1);
	}
	param = ft_split_whitespaces(data);
	wt = 300;
	(void)pwd;
	if (ft_strcmp(param[0], "ls") == 0)
	{
		user = core(user, data);
		send(user->cs, "SUCCES\n", 7, 0);
		return (1);
	}
	else if (ft_strcmp(param[0], "cd") == 0)
	{
		ft_cd(&user, ft_strsplit(data, ' '));
		//send(user->cs, ft_strjoin(user->pwd, "\n"), ft_strlen(user->pwd) + 1, 0);
		send(user->cs, "SUCCES\n", 7, 0);
		return (1);
	}
	else if (ft_strcmp(param[0], "get") == 0)
	{
		file_get(user, data);
		//send(user->cs, "SUCCES\n", 7, 0);
		return (1);
	}
	else if (ft_strcmp(param[0], "put") == 0)
	{
		file_put(user, param[1]);
		//send(user->cs, "SUCCES\n", 7, 0);
		return (1);
	}
	else if (ft_strcmp(param[0], "pwd") == 0 && param[1] == NULL)
	{
		send(user->cs, ft_strjoin(user->pwd, "\n"), ft_strlen(user->pwd) + 1, 0);
		send(user->cs, "SUCCES\n", 7, 0);
		return (1);
	}
	else if (ft_strcmp(param[0], "quit") == 0 && param[1] == NULL)
	{
		send(user->cs, "Exit\n", 5, 0);
		close(user->cs);
		return (0);
	}
	else
	{
		send(user->cs, "Wrong command\n", 14, 0);
		send(user->cs, "ERROR\n", 6, 0);
	}
	return (1);
}
コード例 #8
0
ファイル: mainJ07.c プロジェクト: vihong/42
int		main(int argc, char** argv)
{
	char**	tab;

	argc = 2;
	tab = ft_split_whitespaces(argv[1]);
	ft_print_words_tables(tab);	
	return (0);
}
コード例 #9
0
ファイル: main.c プロジェクト: sakajo/workspace
int	main(int ac, char **av)
{
		char	**tab;

		if(ac == 2)
		{
				tab = ft_split_whitespaces(av[1]);
				ft_print_words_tables(tab);
		}
		return (0);
}
コード例 #10
0
ファイル: core.c プロジェクト: qmuntada/sh1
t_lenv			*core(t_lenv *env, char *line)
{
	char		**param;

	g_bool = 0;
	param = ft_split_whitespaces(line);
	if (param[0] && check_param(param[0]) == 0)
		exec_core(env, param);
	else if (param[0] && check_param(param[0]) == 1)
		env = ft_parse(env, param);
	if (g_bool != 2)
		print_prompt();
	g_bool = 0;
	return (env);
}
コード例 #11
0
int	main()
{
	char str[100] = "Ia sa vedem cat de bine	merge \t acest\n	program";
	char **mat;
	int i;

	mat = ft_split_whitespaces(str);
	i = 0;
	while (mat[i])
	{
		printf("%s", mat[i]);
		i++;
	}
	return (0);
}
コード例 #12
0
ファイル: main.c プロジェクト: Marrylup/42_Piscine_July2015
int	main(void)
{
//	int tab[1];
	int i;
	char **c;
	char str[] = "  Je    veux \t tester   si           ca  \n  fonctionne";
	printf("%d\n", get_nb_words(str));
//	i = get_location(5, str, tab);
//	printf("Size: %d / Beg: %d\n", tab[0], i);
	c = ft_split_whitespaces(str);
	i = 0;
	while (c[i]){
		printf("%s\n", c[i]);
		i++;
	}
	return (0);
}
コード例 #13
0
ファイル: ft_param_to_tab.c プロジェクト: ckor/malibc
struct s_stock_par			*ft_param_to_tab(int ac, char **av)
{
	struct s_stock_par		*ret;
	int				i;

	ret = (struct s_stock_par *)malloc(sizeof(t_stock_par) * (ac + 1));
	if (!ret)
		return (ret);
	i = 0;
	while (i < ac)
	{
		ret[i].size_param	= ft_strlen(av[i]);
		ret[i].str		= av[i];
		ret[i].copy		= ft_strdup(av[i]);
		ret[i].tab		= ft_split_whitespaces(av[i]);
		i++;
	}
	ret[i].str = 0;
	return (ret);
}
コード例 #14
0
struct s_stock_par		*ft_param_to_tab(int ac, char **av)
{
	struct s_stock_par	*stock;
	int					i;

	i = 0;
	stock = (t_stock_par *)malloc(sizeof(t_stock_par) * (ac + 1));
	if (!stock)
		return (NULL);
	while (i < ac)
	{
		stock[i].size_param = ft_strlen(av[i]);
		stock[i].str = av[i];
		stock[i].copy = ft_strdup(av[i]);
		stock[i].tab = ft_split_whitespaces(av[i]);
		i++;
	}
	stock[i].str = 0;
	return (stock);
}
コード例 #15
0
ファイル: main.c プロジェクト: miniponps/42-Piscine-C
int		main(int argc, char **argv)
{
	int i;
	argc = 1;
	i = 0;
	argv = ft_split_whitespaces(argv[1]);
	while(argv[i])
	{
		printf("%s\n", argv[i]);
		i++;
	}
	i = 0;
	printf("\n==================================\n\n");
	ft_sort_wordtab(argv);
	while (argv[i])
	{
		printf("%s\n", argv[i]);
		i++;
	}
	return (0);
}
コード例 #16
0
ファイル: extract_label.c プロジェクト: magouin/Corewar
char		*extract_label(char **line)
{
	char	**parts;
	int		i;
	char	*tmp;
	char	*label;

	tmp = *line;
	parts = ft_split_whitespaces(tmp);
	label = ft_strdup(parts[0]);
	i = 0;
	while (parts[i])
		free(parts[i++]);
	free(parts);
	if (label != NULL && label_format(label))
	{
		return (get_label_value(line, label, tmp));
	}
	free(label);
	return (NULL);
}
コード例 #17
0
struct s_stock_par	*ft_param_to_tab(int ac, char **av)
{
	t_stock_par *stock;
	int			i;
	int			j;

	i = 0;
	stock = malloc(sizeof(t_stock_par) * (ac + 1));
	while (i < ac)
	{
		j = 0;
		while (av[i][j])
			j++;
		stock[i].size_param = j;
		stock[i].str = av[i];
		stock[i].copy = ft_strdup(av[i]);
		stock[i].tab = ft_split_whitespaces(av[i]);
		i++;
	}
	stock[i].str = 0;
	return (stock);
}
コード例 #18
0
t_stock_par			*ft_param_to_tab(int ac, char **av)
{
	t_stock_par	*p;
	int			i;
	int			len;

	p = (t_stock_par *)malloc((ac + 1) * sizeof(t_stock_par));
	i = 0;
	while (i < ac)
	{
		len = ft_strlen(*(av + i));
		(p + i)->size_param = len;
		(p + i)->str = (char *)malloc((len + 1) * sizeof(char));
		(p + i)->str = *(av + i);
		(p + i)->str[len] = '\0';
		(p + i)->copy = (char *)malloc((len + 1) * sizeof(char));
		(p + i)->copy = ft_strdup(*(av + i));
		(p + i)->tab = ft_split_whitespaces(*(av + i));
		i++;
	}
	(p + ac)->str = 0;
	return (p);
}
コード例 #19
0
ファイル: ft_split_whitespaces.c プロジェクト: SuckMyCode/42
int		main(void)
{
	ft_split_whitespaces("Salut gros");
	return (0);
}
コード例 #20
0
ファイル: client.c プロジェクト: qmuntada/ft_p
int main(int argc, char **argv)
{
	int						port;
	int						r;
	char					buff[1024];
	char					*line;
	int						wt;
	char					**param;
	int						fd;

	wt = 0;
	r = 0;
	if (argc != 3)
		usage(argv[0]);
	port = ft_atoi(argv[2]);
	g_sock = create_client(argv[1], port);
	signal(SIGINT, (void(*)())handler);
	ft_putstr(C_NONE);
	ft_putstr(C_BOLD);
	ft_putstr("ft_p >> ");
	ft_putstr(C_NONE);
	ft_putstr(C_GRAY);
	while ((r = read(0, buff, 1024)) > 0)
	{
		ft_putstr(C_NONE);
		ft_putstr(C_GREEN);
		buff[r] = '\0';
		param = ft_split_whitespaces(buff);
		send(g_sock, buff, ft_strlen(buff), 0);
		if (ft_strcmp(buff, "quit\n") == 0)
		{
			close(g_sock);
			exit(0);
		}
		ft_bzero(buff, 1024);
		if (param[0] && ft_strncmp("get", param[0], 3) == 0)
		{
			if ((get_next_line(g_sock, &line)) > 0)
			{
				write(1, line, ft_strlen(line));
				if (ft_strncmp(line, "FAILURE", 7) == 0)
				{
					write(1, "Error -> Could not open or create the file\n", 43);
				}
				else if (ft_strncmp(line, "SUCCESS", 7) == 0)
				{
					if ((fd = open(param[1], O_RDWR | O_CREAT | O_TRUNC, 0777)) == -1)
						write(1, "Error -> Could not open or create the file\n", 43);
					else
					{
						ft_bzero(buff, 1024);
						int		b = 0;
						if ((get_next_line(g_sock, &line)) > 0)
							b = ft_atoi(line);
						int		maxsize = 0;
						ft_bzero(buff, 1024);
						while ((r = recv(g_sock, buff, 1024, 0)) > 0)
						{
							maxsize += r;
							buff[r] = '\0';
							write(fd, buff, r);
							ft_bzero(buff, 1024);
							if (maxsize >= b)
								break;
						}
					}
					close(fd);
				}
			}
		}
		else if (param[0] && ft_strncmp("put", param[0], 3) == 0)
		{
			if (param[1])
				put_file(param[1]);
			else
			{
				write(1, "Error -> Need a file name as second parameter\n", 43);
			}
		}
		else
		{
			while ((r = get_next_line(g_sock, &line)) > 0)
			{
				if (ft_strcmp("SUCCES", line) == 0)
				{
					write(0, "\nSUCCES\n", 8);
					break;
				}
				else if (ft_strcmp("ERROR", line) == 0)
				{
					write(0, "\nERROR\n", 7);
					break;
				}
				printf("%s\n", line);
			}
		}
		r = 0;
		ft_putstr(C_NONE);
		ft_putstr(C_BOLD);
		ft_putstr("ft_p >> ");
		ft_putstr(C_NONE);
		r = 0;
		ft_putstr(C_GRAY);
	}
	close (g_sock);
	return 0;
}