-
Programming question...
I couldnt quite figure out where to ask this question, since there isint a Newbie Programming area, so I figured here was the safest place.
I'm writing a program in c which determines the volume of cylinders made from PVC. I have three large arrays that store the Inside Diameter of Schedule 40,80, and 120 pipe. Is there an easier way than having such large arrays, perhaps reading the values from a file? I'm still very new to C so any help is greatly appreciated
-
You could read the values from the file or you could use pointers to dynamicly allocate the space needed for the array values at run time. But the easiest way to do what you are with 3 large arrays.
Hope that helps,
Cheers,
-D
-
Hardcoding data in usually not (ok.. never...) a good idea. The best place for data is in a database which you will query at runtime.
However, if the program you are making isn't meant to used in a production environment, you could go with an easier option like storing that data in a file (like dspeidel suggested).
Of course the really easiest option is to hardcode your data as arrays in your program, but this really isn't ideal. (Example: if any of that data changes for any reason, you'll have to recompile the program. It might be acceptable for you, but if the program is used by other users, that's unacceptable...)
Ammo
-
If you care more about efficient memory management, I would recommend using pointers to create a linked-list rather than using arrays. Arrays, for the most part, are statically allocated, and you then have the problem that you either have too much space in the array (wasting valuable memory) or you don't have enough (and you'll end up with an overflowing buffer, if you don't handle the checks properly). Dynamically allocating the array is a possibility, but it's a lot more coding. In my opinion, linked lists would be the way to go.
AJ
-
thanx you guys, im firing up google to find out more on those areas right now.