Skip to content

Instantly share code, notes, and snippets.

@lane-s
Last active April 17, 2018 18:34
Show Gist options
  • Save lane-s/8ed64513892ee420fe9df299a73b7dd9 to your computer and use it in GitHub Desktop.
Save lane-s/8ed64513892ee420fe9df299a73b7dd9 to your computer and use it in GitHub Desktop.
int fillArr(Command* arr){
int actual_num_commands = 6;
int i;
for(i = 0; i < actual_num_commands; i++){
arr[i].name = "foo";
arr[i].args[0] = "foo";
arr[i].args[1] = "bar";
}
return actual_num_commands;
}
int printArr(Command* arr, n){
int i;
for(i = 0; i < n; i++){
printf("Command %d is %s\n", arr[i].name);
}
return 0;
}
int main(){
int max_commands = 50;
Command* cmdArr = calloc(max_commands, sizeof(Command));
int n = fillArr(cmdArr, max_commands); //Equivalent to the parsing function
if(n > 0){
printArr(cmdArr, n); //Equivalent to the function that does the interpreting
}
free(cmdArr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment