Skip to content

Instantly share code, notes, and snippets.

@uplime
Created June 12, 2026 17:21
Show Gist options
  • Select an option

  • Save uplime/5bf58dc5978f8a906178ed3b87ca1eca to your computer and use it in GitHub Desktop.

Select an option

Save uplime/5bf58dc5978f8a906178ed3b87ca1eca to your computer and use it in GitHub Desktop.
Display lines of input with every word reversed.
#include <ctype.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
for(argc -= 1, argv += 1; *argv; argc -= 1, argv += 1) {
char *idx = *argv;
char *begin = NULL;
char *end = NULL;
for(; *idx; idx += 1) {
if(isalpha(*idx)) {
if(!begin) {
begin = idx;
}
end = idx;
} else {
for(; end && end >= begin; end -= 1) {
fputc(*end, stdout);
}
if(begin) {
begin = NULL;
end = NULL;
}
fputc(*idx, stdout);
}
}
for(; end && end >= begin; end -= 1) {
fputc(*end, stdout);
}
fputc('\n', stdout);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment