Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. char **commandParser(char *command)
  2. {
  3.  
  4.  
  5. int i=0;
  6. char** paramets;
  7.  
  8. int sizecommand=0;
  9. sizecommand=strlen(command);
  10.  
  11. int numberspaces=0;
  12. for(i=0;i<sizecommand;i++)
  13. {
  14. numberspaces++
  15. }
  16.  
  17. paramets=(char**)malloc((numberspaces+2) * sizeof(char*));
  18.  
  19. int counter=0;
  20.  
  21. i=0;
  22. int j=0,k=0,help=0;
  23. for(i=0; i<sizecommand;i++)
  24. {
  25. if(command[i]==' ')
  26. {
  27.  
  28. paramets[k]=(char*)malloc((counter+1) * sizeof(char*));
  29. j=0;
  30. help=i-counter;
  31. while(help<i)
  32. {
  33. paramets[k][j]=command[help];
  34. j++;
  35. help++;
  36. }
  37. paramets[k][j]='\0';
  38. counter=0;
  39. k++;
  40. continue;
  41. }
  42. counter++;
  43. }
  44.  
  45. paramets[k+1]=NULL;
  46.  
  47. return paramets;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement