Advertisement
finalshare

magiccode

Jul 10th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement