I have an array of integers.Let's assume int a[5]={1,2,1,2,2};.I want to divide this array into two arrays by extracting some elements of array "a[5]" into some different arrays like "b[2]" and "c[3]",such that int b[2] will contain {1,2} and int c[3] will contain {1,2,2}. How can it be possible using C programming?
sash_kp
0
Newbie Poster
Recommended Answers
Jump to PostI assume you are asking how to partition an array into two sub-arrays. This can be done like this:
void partition(int *src, int srclen, int *a, int alen, int *b, int blen, bool(*part)(int)) { a=malloc(srclen*sizeof(int)); b=malloc(srclen*sizeof(int)); int aindex,bindex; aindex=bindex=0;//set the indices to 0 for (int i=0; i<srclen; …
All 3 Replies
Labdabeta
182
Posting Pro in Training
Featured Poster
David W
131
Practically a Posting Shark
David W
131
Practically a Posting Shark
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.