#define SPACE 0x20
int string_size(char *string){
int i = 0;
while (string[i] != '\0')
i++;
return i;
}
char *reverse_words(char *my_string){
int i, size =0;
int j, word_size =0;
size = string_size(my_string);
int k = 0; /* pointer to result string */
char *reverse_string = malloc (size+1);
reverse_string[size] = '\0';
for (i=0; i<size; i++) {
if((my_string[size-1-i] == SPACE)){
for (j = 0; j < word_size; j++){
reverse_string[k] = my_string[size-i+j];
k++;
// printf("%s",reverse_string);
}
reverse_string[k] = my_string[size-1-i];
k++;
word_size = 0;
} else if (i == (size-1)){
for (j = 0; j <= word_size; j++,k++)
reverse_string[k] = my_string[0+j];
break;
} else {
word_size++;
}
}
printf("\"%s\"\n",reverse_string);
return reverse_string;
}
int main(){
char *my_string1 = "The webpage might be temporarily down or it may have moved permanently to a new web address";
printf("\"%s\"\n",my_string1);
reverse_words(reverse_words(my_string1));
char *my_string2 = "conditions";
printf("\"%s\"\n",my_string2);
reverse_words(reverse_words(my_string2));
char *my_string3 = "I ";
printf("\"%s\"\n",my_string3);
reverse_words(reverse_words(my_string3));
return 1;
}