Skip to content

Instantly share code, notes, and snippets.

@iomonad
Last active January 8, 2018 14:09
Show Gist options
  • Save iomonad/8df5f65963b5cb6c65b85acd01410dc2 to your computer and use it in GitHub Desktop.
Save iomonad/8df5f65963b5cb6c65b85acd01410dc2 to your computer and use it in GitHub Desktop.
static void
_revwstr_(char *str, int first)
{
int start;
int i = 0;
if (str[i]) {
while (str[i] && (str[i] == ' ' || str[i] == '\t'))
i++;
if (!str[i])
return ;
start = i;
while (str[i] && (str[i] != ' ' && str[i] != '\t'))
i++;
_revstr(&s[i], 0);
write(1, &str[start], i - start);
if (!first)
write(1, " ", 1);
}
}
static void
_revwstr_(char *str, int first)
{
int start;
int i = 0;
if (str[i]) {
/* Incrementation vers le premier mot */
while (str[i] && (str[i] == ' ' || str[i] == '\t')) {
i++;
}
if (!str[i]) {
return ;
}
/* Keep start in reference */
start = i;
/* Incrementation sur le premier mot */
while (str[i] && (str[i] != ' ' && str[i] != '\t')) {
i++;
}
/* Recurse operation to start at last word */
_revstr(&s[i], 0);
/* Print last word first word */
write(1, &str[start], i - start);
/* Helper to pass on first word */
if (!first) {
write(1, " ", 1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment