Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. void sortDelim(char str[], const char* delim){
  2.     int i,temp,flag,end,first=0,second=0, strlength, wordscounter, copywordscounter;
  3.     strlength=strilength(str);
  4.     signsreplacer(&str[0], &delim[0]); // replacing any non-numbers chars with ;
  5.     wordscounter=wordsamount(&str[0]); //counting words
  6.     wordscounter--;
  7.     copywordscounter=wordscounter;
  8.     while(wordscounter>0){
  9.         while(copywordscounter>0){
  10.             i=first;
  11.             while(str[first]!=';'&&str[first]>0) first++;
  12.             temp=first;
  13.             second=first+1;
  14.             while(str[second]!=';'&&str[second]>0)second++;
  15.             end=second-1;
  16.             flag=strcmp(&str[0],i,second-1); // checking if the I'll have to swap
  17.             if(flag==1){
  18.                 if(end-first>first-i)temp=first+((end-first)-(first-i)); //saving the new ";" position
  19.                 else if(end-first<first-i)temp=first+((end-first)-(first-i)); //saving the new ";" position
  20.             }
  21.             swapwords(&str[0],i,second-1); //swapping words
  22.             first=temp;
  23.             first++;
  24.             copywordscounter--;
  25.         }
  26.         first=0;
  27.         wordscounter--;
  28.         copywordscounter=wordscounter;
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement