eg0rmaffin

sort_params

Sep 4th, 2019
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. #include <unistd.h>
  2.  
  3. void    ft_putchar(char c)
  4. {
  5.     write(1, &c, 1);
  6. }
  7.  
  8. void    ft_putstr(char *str)
  9. {
  10.     int runner;
  11.  
  12.     runner = 0;
  13.     while (*(str + runner) != '\0')
  14.     {
  15.         ft_putchar(*(str + runner));
  16.         runner++;
  17.     }
  18. }
  19.  
  20. int ft_strcmp(char *s1, char *s2)
  21. {
  22.     int run;
  23.     int res;
  24.  
  25.     run = 0;
  26.     while ((s1[run] != '\0') && (s2[run] != '\0'))
  27.     {
  28.         if (s1[run] == s2[run])
  29.             run++;
  30.         else if (s1[run] != s2[run])
  31.         {
  32.             res = s1[run] - s2[run];
  33.             return (res);
  34.         }
  35.     }
  36.     return (0);
  37. }
  38.  
  39. int     main(int argc, char **argv)
  40. {
  41.     int run;
  42.     int i;
  43.     char *tmp;
  44.  
  45.     run = 1;
  46.     while (run != argc)
  47.     {
  48.         i = 1;
  49.         while (i != argc - 1)
  50.         {
  51.             if (ft_strcmp(argv[i], argv[i + 1]) > 0)
  52.             {
  53.                 tmp = argv[i + 1];
  54.                 argv[i + 1] = argv[i];
  55.                 argv[i] = tmp;
  56.             //    i++;
  57.             }
  58.             // if (ft_strcmp(argv[i], argv[i + 1]) <= 0)
  59.                 i++;
  60.         }
  61.         run++;
  62.     }
  63.     run = 1;
  64.     while (run != argc)
  65.     {
  66.         ft_putstr(argv[run]);
  67.         ft_putchar('\n');
  68.         run++;
  69.     }
  70.  
  71.     return (0);
  72. }
Advertisement
Add Comment
Please, Sign In to add comment