Untitled


SUBMITTED BY: Guest

DATE: Nov. 25, 2014, 6:01 p.m.

FORMAT: C++

SIZE: 852 Bytes

HITS: 1142

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. void smarty(char*str)
  5. {
  6. char* word1=strtok(str," ");
  7. char* newstr=(char*)malloc(strlen(word1)+1);
  8. char* word2=strtok(NULL," ");
  9. while(str!=NULL)
  10. {
  11. if(strcmp(word1,word2)==0)
  12. {
  13. newstr=(char*)realloc(str,strlen(str)+strlen(word1)+1);
  14. strcat(newstr," ");
  15. strcat(newstr,word1);
  16. }
  17. else
  18. {
  19. newstr=(char*)realloc(str,sizeof(newstr)+(sizeof(word1))+(sizeof(word2)));
  20. strcat(newstr," ");
  21. strcat(newstr,word1);
  22. strcat(newstr," ");
  23. strcat(newstr,word2);
  24. }
  25. word1=strtok(NULL," ");
  26. word2=strtok(NULL," ");
  27. str+=strlen(word1)+strlen(word2)+2;
  28. }
  29. }
  30. void main()
  31. {
  32. char str[]="penis burger burger vurger penis";
  33. smarty(str);
  34. getch();
  35. }

comments powered by Disqus