hello
i wonder if there is a way to return an array in function
like in java lang for example: int[] ret (int i,int j) {
int[] a = (i,j} ;
return a ;
}
or can i ewturn a pointer to a new array?

i need it for function i wrote
the function reduces duplicate values in array

void noDup[] ( int A[] , int n ) {

  int i , j , k , s ;

  k = n ;

  for ( i=0 ; i<n ; i++ ) {

    for ( j=0 ; j<n ; j++ )

      if ( A[i] == A[j] ) {

           for ( s=j ; s<n-1 ; s++ )

             A[s] = A[s+1] ;

        k-- ;

        } // end if

  } // end for

  int tmp[k] ;

  for ( i=0 ; i<k ; i++ )

    tmp[i] = A[i] ;

  A = tmp ;

  } // noDup end

thank you

You can return a pointer to the allocated array

int* foo()
{
    int* array = malloc( number_elements * sizeof(int) );
    // do something with the array


    return array;
}

thanks Dragon

Don't forget that you'll have to free() the array when you are done with it.

int *array_without_doubles = remove_doubles( array_with_doubles );
print_array( array_without_doubles );
free( array_without_doubles );

Good luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.