•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 456,610 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,487 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 372 | Replies: 3
![]() |
•
•
Join Date: Nov 2007
Posts: 83
Reputation:
Rep Power: 2
Solved Threads: 0
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
thank you
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
c Syntax (Toggle Plain Text)
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
Last edited by Ancient Dragon : Nov 10th, 2007 at 12:24 pm. Reason: add code tags
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,541
Reputation:
Rep Power: 40
Solved Threads: 972
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;
}•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
Don't forget that you'll have to free() the array when you are done with it.
Good luck.
C Syntax (Toggle Plain Text)
int *array_without_doubles = remove_doubles( array_with_doubles ); print_array( array_without_doubles ); free( array_without_doubles );
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- (reformatted) How to return Multi-Dimensional Arrays (C++)
- What relation does **indirection operator have with Multidimensional Arrays (C++)
- Arrays (C++)
- How to Return Multidimensional Arrays (C++)
- C file input/output 2D arrays. (C)
- passing arrays in visual basic (Visual Basic 4 / 5 / 6)
Other Threads in the C Forum
- Previous Thread: math program
- Next Thread: Converting Any Base to Any Base



Linear Mode