rendered paste body#include <stdio.h>
#include <malloc.h>
#include <string.h>
int main(int argc, char * argv[]) {
if (argc < 2) {
printf("No arguments given, cannot continue\n");
return 1;
}
char * line = argv[1];
printf("line is '%s'\n", line);
// reverse the line of stuff
char delimit = ' ';
int ii = 0, jj = 0;
char temp;
int i_first = 0, i_last;
for (ii = 0; ii < strlen(line); ++ii) {
if (line[ii] == delimit) {
i_last = ii - 1;
// reverse the word now
for (jj = 0; jj < (ii - i_first) / 2; ++jj) {
temp = line[jj + i_first];
line[jj + i_first] = line[i_last - jj];
line[i_last - jj] = temp;
}
// done, set the i_first now
i_first = ii + 1;
}
}
printf("i_ifrst is %i\n", i_first);
// need to reverse the last word as well
i_last = strlen(line);
// reverse the word now
for (jj = 0; jj < (i_last - i_first) / 2; ++jj) {
temp = line[jj + i_first];
line[jj + i_first] = line[i_last - jj];
line[i_last - jj] = temp;
}
printf("reversed line is:\n%s\n", line);
return 0;
}