I have an array ‘y’ with x no. of elements inside it (the number ‘x’ is given by user), I need to create an array of structures which has elements of exactly the same type as that in array ‘y’ i.e the array of structures would have ‘x’ elements.
Share
If I understand you right, you have an “array” of some type, and the number of elements is decided by the user. I’m guessing you allocate it using
malloclike this:And now you want to create a similar “array” from a structure, with the same number of elements. Why can’t you do it just like you do for
y? I.e: