As far as I understand your question, you want to return an array that is allocated in another function: here is a simple version of this
#include<stdio.h> #include<stdlib.h> int* set(int *list) { int count, i; printf("Enter number:\n"); scanf("%d", &count); list = (int *) malloc ( sizeof (int) * count); for ( i = 0; i<count;i++ ) { list[i] = 123; } return list; } int main ( int argc, char ** argv ) { int *list; list = set(list); //Use whatever you want to do with that array free(list); // don't forget to free return 0; }
source share