Skip to content

Commit

Permalink
Update last_word.c
Browse files Browse the repository at this point in the history
  • Loading branch information
emreakdik authored Mar 16, 2023
1 parent 42b9e3b commit 2d868b4
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions .resources/rank02/level1/last_word/last_word.c
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@

#include <unistd.h>

int main(int ac, char **av)
void last_word(char *str)
{
int i;
int j = 0;
int i = 0;

i = 0;
if (ac == 2)
while (str[i])
{
if (str[i] == ' ' && str[i + 1] >= 33 && str[i + 1] <= 126)
j = i + 1;
i++;
}
while (str[j] >= 33 && str[j] <= 127)
{
while (av[1][i] != '\0')
i++;
i--;
while ((av[1][i] == ' ' || av[1][i] == '\t') && i != 0)
i--;
while (av[1][i] != ' ' && av[1][i] != '\t' && i != 0)
i--;
if (av[1][i] == ' ' || av[1][i] == '\t')
i++;
while (av[1][i] != '\0' && av[1][i] != ' ' && av[1][i] != '\t')
{
write(1, &av[1][i], 1);
i++;
}
write(1, &str[j], 1);
j++;
}
}

int main(int argc, char **argv)
{
if (argc == 2)
last_word(argv[1]);
write(1, "\n", 1);
}
return (0);
}

0 comments on commit 2d868b4

Please sign in to comment.