Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define maxCommandLength 80
  5. #define maxCommands 100
  6. char command[maxCommands][maxCommandLength];
  7.  
  8. int main(int argc, char **argv) {
  9. if(argc == 1){
  10. printf("No commands provided");
  11. return(-1);
  12. }
  13. //Initialization
  14.  
  15. int commandCurrentCounter = 0;
  16. int commandTotal = 0;
  17.  
  18. //loop to initialize command array
  19. for(int i = 0; i < maxCommands; i++){
  20. command[i][0] = '\0';
  21. }
  22. //Loop to parse argvs into command array
  23. for(int i = 0; i < argc; i++){
  24. char *cur_command = command[commandCurrentCounter];
  25. if(argv[i][0] != '.'){
  26. strcat(cur_command, argv[i]);
  27. strcat(cur_command, " ");
  28. }
  29. else{ //is a dot, terminating the command
  30. if(strlen(cur_command) > 0){
  31. commandCurrentCounter++;
  32. }
  33. }
  34. }
  35. if(strlen(command[commandCurrentCounter]) == 0){
  36. commandTotal = commandCurrentCounter;
  37. }
  38. else{
  39. commandTotal = commandCurrentCounter + 1;
  40. }
  41.  
  42. //Print out Command Array Debug
  43. for(int i = 0; i < commandTotal; i++){
  44. printf("command[%d] = \"%s\"\n", i, command[i]);
  45. }
  46.  
  47.  
  48.  
  49. //Issue Commands
  50.  
  51.  
  52. //Wait and Restart Loop
  53.  
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement