Next Meeting: July 7: Social gathering Next Installfest: TBD Latest News: Jun. 14: June LUGOD meeting cancelled Page last updated: 2003 Oct 30 14:06
 The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers. Report this post as spam: (Enter your email address)
Re: [vox-tech] C-Newbie needs help with a source-code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

# Re: [vox-tech] C-Newbie needs help with a source-code

At 06:06 AM 10/30/2003, you wrote:
what the program is about: you may input a decimal number and the program will convert it into a dual number... after this it will determine the length of the dual number (bestimme_laenge() ) then it should declare an array Dec[] with last position --> lange-1 then the positions Dec[i] ... i++ were filled in while while() after this it shut put out the positions of the array from Dec[lange] to Dec[0] so that the dual number is in the right order... but there are more numbers in the output the array shoul be long... o.O thats what i don't understand... i hope you can help me with this prob... greetz DaRkI sorry, my english is bad.. i know... but I hope you'll understand what i mean ;)

OK, but you're not giving us a whole lot to work with here. Let's break this into smaller problems.

So: you need to convert a decimal number into a binary number, then fill a variable-length array with the binary digits? And you don't know how big it's going to be?
Now, the problem here is that plain C will not allow you to declare new variables in the middle of a program (though C++ will). Your question seems to be: how do I know how big to make it? I can think of two different approaches:
1. Dynamic memory allocation. At the top of your program, declare a pointer (int *i) or an empty array (int i[]). Once you know how big the binary number is going to be, use malloc() to assign some memory to that pointer.
2. Use your brain. What's the biggest number a single integer variable can store? Why? How is this related to the largest size your array will ever be? Hint: look up sizeof(int) on your computer.

Hope this helps.

--nicole twn

_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech

 LUGOD Group on LinkedIn Sign up for LUGOD event announcements Your email address: LUGOD Group on Facebook 'Like' LUGOD on Facebook:

 Hosting provided by: Sunset Systems Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development. LUGOD: Linux Users' Group of Davis PO Box 2082, Davis, CA 95617 Contact Us LUGOD is a 501(c)7 non-profit organization based in Davis, California and serving the Sacramento area. "Linux" is a trademark of Linus Torvalds. Sponsored in part by: For donating some give-aways for our meetings.