I know that I’m not supposed to do this in C90, and it’s a rather basic stuff.
char name[strlen(s)];
ArrayLength.c:11: warning: ISO C90 forbids variable length array ‘name’
Did they want me to specifically use malloc? I’m just curios here about the logic behind it.
It’s forbidden because C90 doesn’t support variable-length arrays (VLAs). It’s really as simple as that.
Your options are:
malloc).malloc, there’s no concept of being able to check that the allocation was successful).[Note: If you’re allocating an array in order to make a copy of
s, you’ll need to usestrlen(s)+1as the size (remember the null terminator).]