Here is the processed document with the code block restored and formatted:
Problem.
Write an algorithm that inverse a line of text without inversing the word.
Solution.
#include <stdio.h>
#include <string.h>
int main() {
char input[256];
char output[256];
int iInput;
int iOutput;
int j;
int k;
int len;
gets(input);
strcpy(output, input);
len = strlen(input);
iInput = len;
iOutput = 0;
// String reversing
while (iInput != 0) {
j = iInput - 1;
while ((input[j] != ' ') && (j != 0)) {
j--;
}
if (j == 0) {
for (k = j; k <= iInput; k++) {
output[iOutput] = input[k];
iOutput++;
}
iInput = 0;
} else if (input[j] == ' ') {
for (k = j + 1; k < iInput; k++) {
output[iOutput] = input[k];
iOutput++;
}
output[iOutput] = ' ';
iOutput++;
iInput = j;
}
}
printf("%s", output);
return 0;
}Result
this is line of text
text of line is this
http://www.AssignmentExpert.com/</string.h></stdio.h>
Comments