I've been trying for days to get these functions right, but in vain. Recursion is not really my thing, and I can't figure these out at all. Any help would be greatly appreciated.
I have to mandatorily use recurison, and the specified function header. So, that also means no loops or other function calls.
1. int file2array(FILE *f, int a)
This takes in a file pointer f and a 1D array a. By calling this function in the main function, the integers in the file “unsorted1.dat (which is given)” are transferred into the elements of a 1D array a1 (one integer to each array element) declared in the main function. Do the same to transfer the integers in file “unsorted2.dat” into the elements of another 1D array a2 declared in the main function. The function returns the number of integers that are scanned from a file into an array.
Rules: You are NOT allowed to use loops or call other functions except file2array, fscanf, and feof.
Example: The file “unsorted2.dat” contains the numbers 7 3 14 6 such that a space separates two integers. This function will assign 7 to a2, 3 to a2, 14 to a2, and 6 to a2. You do NOT need to worry about what the values are in the rest of the elements of array a2.
2. int small(int a, int n)
This one takes in a 1D array a and the array size n. This function returns the index of the smallest integer in array a. Assume n > 0.
Rules: You are NOT allowed to use loops or call other functions except small.
I know that was long, but please help! Oh, I read that homework policy part, but I really don't even know where to start with these. Anyway, if this really annoyed you, very sorry.