示例#1
0
void		get_data(char *path)
{
	DIR			*rep;
	t_dirent	*fr;
	t_file		*dir;
	char		*tmp;

	rep = opendir(path);
	dir = lst_new(path, path, 2);
	if (rep != NULL)
	{
		while ((fr = readdir(rep)) != NULL)
		{
			tmp = ft_strdup(fr->d_name);
			lst_push(lst_new(tmp, path, 0), &dir);
			free(tmp);
		}
		closedir(rep);
	}
	else
	{
		ft_error(path);
		return ;
	}
	while (dir->next->next != NULL)
		dir = dir->next;
	data_proc(dir);
}
示例#2
0
int executaOperacao(list_t *pilha, char op)
{
	float resultado;
	int valido = 0;
	valido = 1;
	lst_iitem_t *aux1 = lst_pop(pilha);
	float a1 = aux1->value;
	aux1 = lst_pop(pilha);
	float b1 = aux1->value;
	if((op == ':' || op == '/') && a1 == 0){
		printf("Resultado: DIVISAO POR ZERO\n");
		return 0;
	}
	resultado = fazConta(a1,b1,op);
	lst_push(pilha,resultado);
	return 1;	
}
示例#3
0
void leOperacao(list_t *pilha)
{
	char op;
	char *buffer;
	char *componentes;
	int valido;
	float numero;
	buffer = (char *) malloc(MAX);
	componentes = (char *) malloc(MAX);
	printf("> ");
	fgets(buffer,MAX-1,stdin);
	buffer[strlen(buffer)-1]='\0';
	if(strlen(buffer) >= MAX){
		printf("Resultado: OPERAÇÃO NÃO VÁLIDA.\n");
		return;
	}
	if(strlen(buffer) == 0){
		printf("Resultado: OPERAÇÃO NÃO VÁLIDA.\n");
		return;
	}
	componentes = strtok(buffer, " ");
	while (componentes != NULL) {
		if(strlen(componentes)==1){
			if(!isdigit(componentes[0])){
				op = componentes[0];
				if(op == '+' || op == '-' || op == '*' || op == 'x' || op == ':' || op == '/'){
					// It is an operator
					if(lst_lenght(pilha) > 1){
						valido = executaOperacao(pilha, op);
						if(!valido)
							return;
					} else {
						printf("Resultado: FALTAM OPERANDOS.\n");
						return;
					}
				}
				else{
					printf("Resultado: OPERAÇÃO NÃO VÁLIDA.\n");
					return;
				}
			}
			else{
				op = atoi(componentes);
				lst_push(pilha,op);
			}
		}
		else{

			numero = atof(componentes);
			if(numero == 0){
				printf("Resultado: OPERAÇÃO NÃO VÁLIDA.\n");
				return;
			}
			else{
				lst_push(pilha,numero);
			}
		}				
		componentes = strtok(NULL," ");
	}
	free(componentes);
	free(buffer);
	if(lst_lenght(pilha) == 1){
		lst_iitem_t* aux = lst_pop(pilha);
		float resultado = aux->value;
		printf("Resultado: %.2f\n", resultado);
	}
	else{
		printf("Resultado: FALTAM OPERADORES.\n");
	}
	return;
}