Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <stdio.h> #include <string.h> #define SIZE 15 void sort(float num[], in

ID: 3774409 • Letter: #

Question

#include <stdio.h>
#include <string.h>
#define SIZE 15
void sort(float num[], int lo, int hi);

int main() {
int i,ok,num[SIZE],num1[SIZE],num2[SIZE];
char str[25];
unsigned long num_id;
FILE *fp;
printf(" ");
fp=fopen("grades.csv", "r");
if(fp==NULL) {
printf("Error opening file - Correct file name is soup.txt ");
printf(" Column separators are commas ");
return 1;
}
i=ok=0;
printf(" Student ID exam1 exam2 exam3 GRADE ");
printf (" ======================================= ");
while(1) {
ok=sscanf(fp, "%lu %d %d %d %*c",
&num_id,&num[i],&num1[i],&num2[i],str);
if(ok < 1)
break;
printf("%lu %d %d %d %*c", &num_id,&num[i],&num1[i],&num2[i],str);
++i;
}
fclose(fp);
putchar(' ');
sort(num, 0, i); //sort num[], through the index
printf(" press enter when ready ");

(void) getchar();
return 0;
}
/* Insertion sort */
void sort(float A[], int lo, int hi) {
int i, j; //the indeces for the array locations
float val; //sorting floats here
int idx[15]; //the index array
for(i=0;i<SIZE;i++) //initialize the index array
idx[i] = i;
  
printf(" The Prices of Soups in their Original Order: ");
for(i=lo;i<hi;i++) printf("%5.2f ",A[idx[i]]); getchar();
for(i=lo+1;i<hi;i++) {
val = A[idx[i]]; //get a value of A[], through the index array
j = i-1;
while(A[idx[j]] > val) {
idx[j + 1] = idx[j];
--j;
if(j<0) break;
}
idx[j+1] = i;   
}
printf(" The Prices of Soups After Insertion Sort: ");
for(i=lo;i<hi;i++) printf("%5.2f ",A[idx[i]]);
getchar();
}

I can't figure out what is wrong with this program, I keep getting the error message posted below.

grades .c: In function amaina: grades. C:23: warning: passing argument 1 of asscanfa from incompatible pointer type /usr/include/stdio.h:452 note expected aconst char restricta but argument is of type astruct FILE grades. C:31: warning: passing argument 1 of asorta rom incompatible pointer type grades. C: 4: note: expected afloat *a but argument is of type aint *a

Explanation / Answer

Hi, I have fixed the compilation issue.

Please let me know in case of any issue.

#include <stdio.h>
#include <string.h>
#define SIZE 15
void sort(float num[], int lo, int hi);
int main() {
int i,ok;
float num[SIZE],num1[SIZE],num2[SIZE];
char str[25];
unsigned long num_id;
FILE *fp;

printf(" ");
fp=fopen("grades.csv", "r");
if(fp==NULL) {
printf("Error opening file - Correct file name is soup.txt ");
printf(" Column separators are commas ");
return 1;
}
i=ok=0;
printf(" Student ID exam1 exam2 exam3 GRADE ");
printf (" ======================================= ");
while(1) {
ok=fscanf(fp, "%lu %f %f %f %s", &num_id,&num[i],&num1[i],&num2[i],str);
if(ok < 1)
break;
printf("%lu %f %f %f %s", num_id, num[i], num1[i], num2[i],str);
++i;
}
fclose(fp);
putchar(' ');
sort(num, 0, i); //sort num[], through the index
printf(" press enter when ready ");
(void) getchar();
return 0;
}
/* Insertion sort */
void sort(float A[], int lo, int hi) {
int i, j; //the indeces for the array locations
float val; //sorting floats here
int idx[15]; //the index array
for(i=0;i<SIZE;i++) //initialize the index array
idx[i] = i;
  
printf(" The Prices of Soups in their Original Order: ");
for(i=lo;i<hi;i++) printf("%5.2f ",A[idx[i]]); getchar();
for(i=lo+1;i<hi;i++) {
val = A[idx[i]]; //get a value of A[], through the index array
j = i-1;
while(A[idx[j]] > val) {
idx[j + 1] = idx[j];
--j;
if(j<0) break;
}
idx[j+1] = i;   
}
printf(" The Prices of Soups After Insertion Sort: ");
for(i=lo;i<hi;i++) printf("%5.2f ",A[idx[i]]);
getchar();
}