Mik0b0 said:
> Hallo everybody,
> my problem is: there are two single-dimension arrays, longer[M] and
> shorter[N], every array is organized in ascending order. We need to
> build a new array out of two. This is what I wrote:
> #include<stdio.h>
> #define M 8
> #define N 5
> main()
> {
> int big[M]={1,2,5,8,10,23,45,56};
> int small[N]={3,7,11,12,100};
> int new[M+N];
> int i=0,k=0,l=0;
>
> while(l<(N+M))
> {
> if(small[k]<big[i])
You don't check to ensure that k < N or that i < M. Once k == N, you need to
stop loading from 'small' and copy the rest of 'big', unless i == M. Once i
== M, you need to stop loading from 'big', and copy the rest of 'small',
unless k == N.
Fix that, and I reckon your problem will vanish.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.