#include #include #include #include "sec2_struct.h" /** * author : jyo2 * exercise to create a struct with passed in command line arguments and then destroy it be freeing the memory * */ #define NUM_ARGS 3 int convert_to_int(char *string, int *result) { return sscanf(string, "%d", result); } int main(int argc, char **argv) { // quit if user does not pass in 2 arguments if (argc != NUM_ARGS) { fprintf(stderr, "incorrect number of arguments for the program"); return EXIT_FAILURE; } // retrieve the arguments to put in the struct int key1_cla, key2_cla; if (!convert_to_int(argv[1], &key1_cla) || !convert_to_int(argv[2], &key2_cla)) { // quit if the user passes bogus input fprintf(stderr, "incorrect argument types, please input decimals"); return EXIT_FAILURE; } // construct the struct with the 2 arguments the user passed Section2StructPtr new_struct = sec2struct_construct(key1_cla, key2_cla); sec2struct_print(new_struct); // free the struct, please!! printf("Now destroying the struct, goodbye :(\n"); sec2struct_destroy(new_struct); // pass in a pointer to new_struct printf("Let try this %d and %d\n", new_struct->key1, new_struct->key2); return EXIT_SUCCESS; }