Question: Write a C function sieve (as well as a driver program) as specified below. int *sieve(int *inlist, int inSize, int n, int *outSize); The function


Write a C function sieve (as well as a driver program) as specified below. int *sieve(int *inlist, int inSize, int n, int *outSize); The function sieve is passed an integer list inlist of inSize size and returns a list of all the values in inlist that are greater than or equal to n. It also passes back the size of this returned list in outSize. If no values in inlist are greater than or equal to n your function should return NULL and outSize will be set to 0. Your function must return a list as an integer array of exactly outSize size, plus you must use use malloc in your function to create this list. Also your function should not modify inlist (the input list) in any way. Steps to complete lab #2: 1. Begin by downloading your data file from Canvas; file lab2.dat contains 1000 randomly generated integers between the range 1200 (inclusive). (There also a program there that you can use to generate random integers if you wish to create a different data set.) 2. Edit this file to include two additional values at the beginning of the file. First add the number of items you wish to use in your data set followed by the value n (see above) that you wish to use to filter your data. 3. Add data input and echo printing to your program. To keep things simple input this data file via standard input through command line redirection as you did often in EGRE245; see the sample run below. 4. Finally write sieve and output the list it returns (or NULL as appropriate). all the data A sample run is given on the next page. Note that all input comes from the file printed out in the sample run is just echo printing this input. Terminal -tcsh 55x12 homebox:~/docs/classes/egre246/% a.out > list size: 7 filtered list: 128 73 175 98 186 73 193 homebox:~/docs/classes/egre246/% Write a C function sieve (as well as a driver program) as specified below. int *sieve(int *inlist, int inSize, int n, int *outSize); The function sieve is passed an integer list inlist of inSize size and returns a list of all the values in inlist that are greater than or equal to n. It also passes back the size of this returned list in outSize. If no values in inlist are greater than or equal to n your function should return NULL and outSize will be set to 0. Your function must return a list as an integer array of exactly outSize size, plus you must use use malloc in your function to create this list. Also your function should not modify inlist (the input list) in any way. Steps to complete lab #2: 1. Begin by downloading your data file from Canvas; file lab2.dat contains 1000 randomly generated integers between the range 1200 (inclusive). (There also a program there that you can use to generate random integers if you wish to create a different data set.) 2. Edit this file to include two additional values at the beginning of the file. First add the number of items you wish to use in your data set followed by the value n (see above) that you wish to use to filter your data. 3. Add data input and echo printing to your program. To keep things simple input this data file via standard input through command line redirection as you did often in EGRE245; see the sample run below. 4. Finally write sieve and output the list it returns (or NULL as appropriate). all the data A sample run is given on the next page. Note that all input comes from the file printed out in the sample run is just echo printing this input. Terminal -tcsh 55x12 homebox:~/docs/classes/egre246/% a.out > list size: 7 filtered list: 128 73 175 98 186 73 193 homebox:~/docs/classes/egre246/%
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
