Reverse the letters in every word
This commit is contained in:
parent
545f926f0b
commit
1d1d439626
|
@ -0,0 +1,36 @@
|
|||
#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);
|
||||
}
|
||||
}
|
||||
|
||||
fputc('\n', stdout);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue