Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdio.h"
- #include "stdlib.h"
- #define size 100
- char* newString(char*, int);
- int len_str(char* string){
- int i = 0;
- while (string[i] != '\0'){
- i++;
- }
- return i;
- }
- int main(){
- char* string = (char*)malloc(sizeof(char)*size);
- gets(string);
- int length=len_str(string);
- string = newString(string, length);
- printf("%s\n", string);
- return 0;
- }
- char* newString(char* string, int length){
- int j = length;
- while (string[--j] == ' ');
- while (string[--j] != ' ');
- while (string[--j] == ' ');
- while (string[--j] != ' ');
- int left = j + 1, right = length - 1;
- while (right >= left){
- char temp = string[left];
- string[left] = string[right];
- string[right] = temp;
- right--; left++;
- }
- int beginFirst = j + 1;
- int endFirst = j + 1;
- while (string[endFirst + 1] != ' '){//watch what symbol will be next
- endFirst++; // then +1 if all is ok
- }
- for (int i = 0; i <= (endFirst - beginFirst) / 2; i++){
- char temp = string[endFirst - i];
- string[endFirst - i] = string[beginFirst + i];
- string[beginFirst + i] = temp;
- }
- int endSecond = length - 1;
- int beginSecond = length - 1;
- while (string[beginSecond - 1] != ' '){
- beginSecond--;
- }for (int i = 0; i <= (endSecond - beginSecond) / 2; i++){
- char temp = string[endSecond - i];
- string[endSecond - i] = string[beginSecond + i];
- string[beginSecond + i] = temp;
- }
- return string;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement