Created
June 12, 2026 17:21
-
-
Save uplime/5bf58dc5978f8a906178ed3b87ca1eca to your computer and use it in GitHub Desktop.
Display lines of input with every word reversed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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