Assignment
#3 – File i/o and sorting
1. Write a function MySortIntegers that reads N (<100) integer values from a text file fileName
into integer array values –
void MyReadIntegers(char*
fileName, int N, int *values)
The file is given in the following format
value_1
value_2
¡¦
value_K
2. Write a function that sorts N (<100) integer values in ascending
order –
void MySortIntegers(int N, int *values);
3. Write a function that
searches a given key value from the sorted values made by question 2 and return
the rank. If no value is found, then it returns -1.
int MySearchInteger(int
*values, int N, int keyValue)
The following program may be useful for
this assignment.
void inputScores(int s[],int n) {
FILE *fp;
int i;
fp=fopen(¡°math.txt¡±,¡±r¡±);
for(i=0;i<n;i++)
if(fscanf(fp,¡±%d¡±, &s[i])==EOF) break; /* if less than n items are read, then
break */;
fclose(fp);
}
Oral
Test: on March 15