Advertisement
Guest User

Untitled

a guest
Sep 11th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main()
  6. {
  7. char **a=malloc(20*sizeof(char*));
  8. char s[500];
  9. for(int i=0;i<20;i++)
  10. {
  11. a[i]=malloc(21*sizeof(char));
  12. }
  13.  
  14. fgets(s,500,stdin);
  15. char *tok=strtok(s," ");
  16. int i=0;
  17. while(tok != NULL && i<20)
  18. {
  19. strcpy(a[i],tok);
  20.  
  21. i++;
  22. tok=strtok(NULL," ");
  23.  
  24. }
  25. char temp[21];
  26. strcpy(temp,a[0]);
  27. strcpy(a[0],a[2]);
  28. strcpy(a[2],temp);
  29. int j=0;
  30. while(a[j]!= i){
  31.  
  32. printf("%s ",a[i]);
  33. j++;
  34.  
  35. }
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement