'A C program that ,given a structure definition, generates a function to allocate and initialise this structure
I found this exercise in an old book on C data structures and it gave the following problem prompt:
- Write a program that, given a structure definition, will generate a C function that allocates and initializes the structure (such a function is called a "constructor"). For example, given the input:
struct complex { double real; double imaginarry; }
function
create_complex()will be created having two arguments of typedouble.
I tried thinking of how to create such a program and my only solution is to use a file to get the struct input and create a new text file in which I write the function.
Is there any other way to approach this problem? I appreciate it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
