HTML & JS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* reverse words in string */

void reverse(char *begin, char *end) {
    char c;
    while(begin != end && begin != end+1) {
        c = *begin;
        *begin = *end;
        *end = c;
        begin = begin+1;
        end = end-1;
    }
}

void reverse_words(char *s) {
    char *end, *begin = s;
    while(end = strpbrk(s, " ")) {
        reverse(begin, end-1);
        s = begin = end+1;
    }
    end = begin;
    while(*(end+1) != '\0') {
        end = end+1;
    }
    reverse(begin, end);
}

int main() {
    int n;
    scanf("%d\n", &n);
	char s[100], temp;
	for(int i = 0; i < n; ++i) {
	    scanf("%[^\n]s", s);
        reverse_words(s);
        printf("%s\n", s);
        scanf("%c", &temp); // clears the buffer
	}
	return 0;
}

Generated URL:

Output:

gnidoc si looc
I tnaw noissimda otni TII yabmoB
OG si a looc etisbew
Report Bug