-
July 18th, 2002, 02:03 PM
#1
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're not your post count, You're not your avatar or sig, You're not how fast your internet connection is, You are not your processor, hard drive, or graphics card. You're the all-singing, all-dancing crap of AO
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
-
July 18th, 2002, 03:14 PM
#2
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
If you spend more on coffee than on IT security, you will be hacked. What\'s more, you deserve to be hacked.
-- former White House cybersecurity adviser Richard Clarke
-
July 18th, 2002, 06:30 PM
#3
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
Credit travels up, blame travels down -- The Boss
-
July 18th, 2002, 06:53 PM
#4
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
-
July 19th, 2002, 03:30 AM
#5
thanx you guys, im firing up google to find out more on those areas right now.
You're not your post count, You're not your avatar or sig, You're not how fast your internet connection is, You are not your processor, hard drive, or graphics card. You're the all-singing, all-dancing crap of AO
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|