From: Hans-Bernhard Broeker Newsgroups: comp.os.msdos.djgpp Subject: Re: Array problems... Date: 20 Oct 2000 12:00:26 GMT Organization: Aachen University of Technology (RWTH) Lines: 25 Message-ID: <8spc4q$5t8$1@nets3.rz.RWTH-Aachen.DE> References: NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de X-Trace: nets3.rz.RWTH-Aachen.DE 972043226 6056 137.226.32.75 (20 Oct 2000 12:00:26 GMT) X-Complaints-To: abuse AT rwth-aachen DOT de NNTP-Posting-Date: 20 Oct 2000 12:00:26 GMT Originator: broeker@ To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Johan wrote: > Hi! > I have some problems with my program. I want to take the numbers in array_a > that are positive. 0 or above. And put these in array_b and print them out. At the moment, your code is putting the *sum* of all such entries into array_b, not the individual ones. Get rid of the 'for (j=...)' loop. > int array_a[] = {3, 2, 7, 0, 5, -4, 8, 7, -1, -9}; > int array_b[7]; > int n = 10; > int m = 7; A side issue: here, you're making assumptions about the number of elements array_b is going to have, i.e. you're using part of the solution to construct the program that is meant to find that solution. You shouldn't do that. Make array_b as big as array_a, instead. Start with m=0, and count it upwards as you find entries for array_b. -- Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de) Even if all the snow were burnt, ashes would remain.