예제 #1
0
char	*my_modulo(char *n1, char *n2)
{
    t_div *d;

    d = init_my_mod(n1, n2);
    if ((d != NULL) && (my_str_isnum(d->dvd) == 1) && (my_str_isnum(d->dvs) == 1))
        if (d->dvs[0] != '0')
        {
            while (d->dvd[0] != '-')
            {
                if ((my_do_op_sub_cmp(d->dvs, d->dvd, 0, 0) == 0) &&
                        (d->mod[0] == '0'))
                    my_strcpy(d->mod, d->dvd);
                my_strcpy(d->temp_cmp, d->dvs);
                my_strcpy(d->temp_fact, "1");
                while (my_do_op_sub_cmp(d->temp_cmp, d->dvd, 0, 0) == 1)
                    add_zero(d);
                (check_digits(d) == 1) ? (add_zero(d)) : (1);
                remove_zero(d);
                if (check_digits(d) == 1)
                    d->temp_fact = add_sub(d->temp_fact, "-1");
                get_minus(d->temp_cmp);
                d->total = add_sub(d->total, d->temp_fact);
                d->dvd = add_sub(d->dvd, d->temp_cmp);
            }
            free(d);
            return (check_neg(d, d->mod, 2, 0));
        }
        else
            my_putstr(DIV_0);
    return (0);
}
예제 #2
0
파일: exit.c 프로젝트: Linezek/42sh
t_uchar		run_exit(char **env,
			 char **path,
			 t_command *command,
			 t_builtin_ptr **builtins)
{
  char		exit_status;

  if (count_args(command->argv_tmp) > 2)
    {
      my_dprintf(STDERR, "exit: Expression Syntax.\n");
      return (EXIT_FAILURE);
    }
  if (command->argv_tmp == NULL || count_args(command->argv_tmp) == 1)
    exit_status = command->last_ret;
  else if (my_str_isnum(command->argv_tmp[1]) == FALSE)
    {
      my_dprintf(STDERR, "exit: Expression Syntax.\n");
      return (EXIT_FAILURE);
    }
  else
    exit_status = my_atoi(command->argv_tmp[1]);
  if (command->interactive == TRUE)
    my_dprintf(STDERR, "exit\n");
  my_free_2d_tab(env);
  my_free_2d_tab(path);
  my_free_2d_tab(command->argv);
  free(command->argv_tmp);
  free_builtins(builtins);
  exit(exit_status);
  return (EXIT_SUCCESS);
}
예제 #3
0
int		_get_lines_nbr(int argc, char **argv)
{
  int		lines;
  int		idx;

  lines = 4;
  idx = 1;
  while (idx < argc)
    {
      if (my_cmp("-l", argv[idx]))
	{
	  if (!my_str_isnum(argv[idx + 1]))
	    {
	      my_dprintf(STDERR, "Numeric argument required with \"-l\"\n");
	      return (-1);
	    }
	  lines = my_atoi(argv[idx + 1]);
	}
      idx += 1;
    }
  if (lines > 256 || lines <= 0)
    {
      my_dprintf(STDERR, "Number of lines out of range! {1..256}\n");
      return (-1);
    }
  return (lines);
}
예제 #4
0
파일: main.c 프로젝트: Thegeiger/Corewar
/*
** brief: get all the parameters for the virtual machine
** @argc: number of arguments pass to the program
** @argv: each arguments pass to the program
** @corewar: our structure for the virtual machine
** return: {0 if succeed} {1 if error during parsing}
*/
static unsigned int	my_get_params(int argc, char **argv, t_corewar *corewar)
{
  t_champion		*champion;
  int			i;

  i = 1;
  if (!my_strcmp(argv[i], "-dump"))
    {
      if (i + 1 >= argc || my_str_isnum(argv[i + 1]) ||
	  (corewar->dump = my_getnbr(argv[i + 1])) < 0)
	return (my_fprintf(2, "Dump must have a positive number.\n"));
      i += 2;
    }
  else
    corewar->dump = -1;
  while (i < argc)
    {
      if (!(champion = my_malloc(sizeof(*champion))))
	return (my_fprintf(2, "At my_get_params : Malloc failed.\n"));
      if (my_champion(argc, argv, &i, champion))
	return (1);
      if (my_order_champion(corewar, champion))
	return (1);
    }
  return (0);
}
예제 #5
0
int	main(int argc, char **argv)
{
  int	*tabstick = NULL;
  
  if (argv[1] && (my_str_isnum(argv[1]) == 0)) 
    {
      tabstick = create_sticktab(argv[1]);
      if (!tabstick) return (0);
      while (42)
	{
	  choose_line(tabstick);
	  aff_sticks(tabstick, my_get_nbr(argv[1]));
	  if (!verif_if_lose(tabstick, my_get_nbr(argv[1])))
	    {
	      my_putstr("You lose . . .\n\n");
	      return (0);
	    }
	  rand_line(tabstick, my_get_nbr(argv[1]));
	  if (!verif_if_lose(tabstick, my_get_nbr(argv[1])))
	    {
	      my_putstr("You win!\n\n");
	      return (0);
	    }
	}
    }
  else my_putstr("\n\tUse a number for argument 1.\n\n");
  return (0);
}
예제 #6
0
int	define_number_line(char *str, int const line_max)
{
  int	i = 0;
  
  if (my_str_isnum(str) == 1)
    return (0);
  i = my_get_nbr(str);
  if (i > line_max)
    return (0);
  return (i);
}
예제 #7
0
char		*is_valid_stats(t_winChampion *data, int i, int j)
{
  const gchar	*text;

  while (i < j)
    {
      text = gtk_entry_get_text(GTK_ENTRY(data->attEntry[i]));
      if (my_str_isnum((char *) text) != 1)
	return ("Bad Champion stats (hp/spe/speed/deg)");
      i++;
    }
  return (NULL);
}
예제 #8
0
static int      check_n(t_program *prgm, int i, int argc, const char **argv)
{
  if (my_match(argv[i], "-n"))
    {
      if (prgm->player_id != -1)
	return (error_int(RET_FAILURE, ERR_N_REPEAT));
      if (i + 1 < argc)
	{
	  if (!my_str_isnum(argv[i + 1])
	      || (prgm->player_id = my_getnbr(argv[i + 1])) < 0)
	    return (error_int(RET_ERROR, ERR_N_INVALID_VAL));
	}
      else
	return (error_int(RET_FAILURE, ERR_N_NO_VAL));
    }
  return (RET_SUCCESS);
}
예제 #9
0
int	check_s2(char *buff, int nbr, int tab_rl)
{
  if (my_str_isnum(buff) == -1)
    {
      my_putstr("Error: You must have to enter positive numbers only !\n");
      my_putstr("How many matches do you want to remove ? ");
      return (1);
    }
  if (nbr > tab_rl || nbr == 0)
    {
      if (nbr == 0)
	my_putstr("Error: You have to take at least one match !\n");
      else
	my_putstr("Error: there is not enough matches !\n");
      my_putstr("How many matches do you want to remove ? ");
      return (1);
    }
  return (0);
}
예제 #10
0
int	main(int ac, char **av)
{
  int	i;
  int	serv_pid;
  char	*str;

  if (ac != 3)
    {
      my_putstr("Usae: ./client [ServerPID] [Message]\n");
      return (0);
    }
  i = 0;
  if (my_str_isnum(av[1]) == -1)
    {
      my_putstr("Usage: The ServerPID is a number only !\n");
      return (0);
    }
  else
    serv_pid = my_getnbr(av[1]);
  str = av[2];
  while (str[i] != '\0')
    binary(serv_pid, str[i++]);
  return (0);
}
예제 #11
0
int	step_one(int *remove_line, int *tab, int tab_size, char *buff)
{
  if (my_str_isnum(buff) == -1)
    {
      my_putstr("Error: You must have to enter positive numbers only !\n");
      my_putstr("On which line would you want to remove matches ? ");
      return (0);
    }
  if (my_getnbr(buff) > 0 && my_getnbr(buff) <= tab_size)
    {
      if (tab[my_getnbr(buff) - 1] == 0)
	{
	  my_putstr("Error: there is no matches in this line !\n");
	  my_putstr("On which line would you want to remove matches ? ");
	  return (0);
	}
      *remove_line = my_getnbr(buff) - 1;
      my_putstr("How many matches do you want to remove ? ");
      return (1);
    }
  my_putstr("Error: The line specified does not exist !\n");
  my_putstr("On which line would you want to remove matches ? ");
  return (0);
}
예제 #12
0
void	check_error_two(char *str)
{
  if (my_str_isnum(str) == 0)
    my_error("After option R or S, you must enter only on number\nExecute ./man_103 to read the man");
}
예제 #13
0
void	check_error_one(char *str)
{
  if (my_str_isnum(str) == 0)
    my_error("After option T or H, you must enter two numbers\nExecute ./man_103 to read the man");
}
예제 #14
0
int	check_size(char **av)
{
  if (my_str_isnum(av[3]) != 1)
    my_putstr_error(SYNTAXE_ERROR_MSG);
  return (0);
}
예제 #15
0
파일: mystrisnum.c 프로젝트: Sun42/lib
int main()
{
    printf("%i",my_str_isnum(""));
    return(0);
}