SHARE
TWEET

magiccode

finalshare Jul 10th, 2017 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3. char* reverseAllWords(char str[])
  4. {
  5.     char * pch;
  6.     char *listWord[100];
  7.     char  result[100]="";
  8.     int index=0;
  9.  
  10.     pch = strtok (str," ");
  11.  
  12.     while (pch != NULL)
  13.     {
  14.         listWord[index] = pch;
  15.         pch = strtok (NULL, " ");
  16.         ++index;
  17.     }
  18.     int i;
  19.  
  20.     for (i=index-1; i>=0; --i)
  21.     {
  22.         strcat(result,listWord[i]);
  23.         strcat(result," ");
  24.         printf("",result);//magic line
  25.     }
  26.     return result;
  27. }
  28. int main ()
  29. {
  30.     char str[100] ;
  31.     gets(str);
  32.     printf("%s",reverseAllWords(str));
  33.     return 0;
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top