Newbie to C. I’m writing an ANSI C program (on Linux using gcc 4.4.6) and need to know how to initilize a numeric array, such as int or double, where the length of the array is determined when the program is run?
Does ANSI C allow one to declare variable, execute some code (wherein the length is determined), then declare additional variables (e.g. the arrays in question)?
If not, how is this done in practice? Note the program compiles using gcc -ansi ... switch.
You need to allocate the memory for the array and free it after you are done.
See malloc and free and get one of the beginner books listed here. Attempting to write C without a solid foundation ends in blood, tears and segfaults. Think of the children. Don’t do it.
Example to get you started with shooting yourself in the foot: