Guest User

Untitled

a guest
Apr 25th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. int fillArr(Command* arr){
  2. int actual_num_commands = 6;
  3. int i;
  4. for(i = 0; i < actual_num_commands; i++){
  5. arr[i].name = "foo";
  6. arr[i].args[0] = "foo";
  7. arr[i].args[1] = "bar";
  8. }
  9. return actual_num_commands;
  10. }
  11.  
  12. int printArr(Command* arr, n){
  13. int i;
  14. for(i = 0; i < n; i++){
  15. printf("Command %d is %s\n", arr[i].name);
  16. }
  17. return 0;
  18. }
  19.  
  20. int main(){
  21. int max_commands = 50;
  22. Command* cmdArr = calloc(max_commands, sizeof(Command));
  23.  
  24. int n = fillArr(cmdArr, max_commands); //Equivalent to the parsing function
  25.  
  26. if(n > 0){
  27. printArr(cmdArr, n); //Equivalent to the function that does the interpreting
  28. }
  29.  
  30. free(cmdArr);
  31. }
Add Comment
Please, Sign In to add comment