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

************URGENT********** Can someone help me with this code? The program ope

ID: 3743481 • Letter: #

Question

 ************URGENT********** Can someone help me with this code? The program opens and runs, but when I try to print out the sorted arrays, none of the menu options function properly. It prints out random numbers.    #include<stdio.h> #include<stdlib.h>   struct array {         char model[50];         int numI;         float numF;         char color[50]; };  struct array list[100]; int count = 0;    void readData() {         FILE *file;         int ch;         int position = 0;         file = fopen("hw2.data","r");          if(file != NULL){         ch = fgetc(file);         while(fscanf(file, "%s %f %d %s", list[position].model, list[position].numF,                  list[position].numI, list[position].color) == 4){                 position++;                 count++; } }         else         {                 printf("Error Reading File ");                 exit(0);         }          }          void sortfloat()//float list[].numF, int count {         int c,g;         for (c = 0; c < count-1; c++)                 for (g =0; g< count - c - 1; g++)                         if(list[g].numF > list[g+1].numF )                         {                                 int temp = list[c].numF;                                 list[c].numF = list[g].numF;                                 list[g].numF = temp;                         }                                           }  void sortint()//int list[].numI, int count) {         int c,g;         for (c = 0; c < count-1; c++)                 for (g =0; g< count - c - 1; g++)                         if(list[g].numI > list[g+1].numI )                         {                                 int temp = list[c].numI;                                 list[c].numI = list[g].numI;                                 list[g].numI = temp;                         }  }          void printhightolow()  {              int i;         for (int i = 100; i > 0; i--)         {                 printf("%s %f %d %s", list[i].model, &list[i].numF,                          &list[i].numI, &list[i].color);         }  }         void printlowtohigh() {         int i;          for (int i = 0; i < 100; i++)         {                 printf("%s %f %d %s", list[i].model, &list[i].numF,                          &list[i].numI, &list[i].color);         }  }             int main() {                               int i;             int choice;              //Loop for the menu options              do              {                                                  printf("  1. Sort data by the float value & print high to low  ");                          printf("  2. Sort data by the float value & print low to high  ");                          printf("  3. Sort data by the int value & print high to low  ");                          printf("  4. Sort data by the int value & print low to high  ");                          printf("  5. Exit  ");                          printf("  Please Enter a number corresponding to one the options: ");                          scanf("%d", &choice);                          switch (choice)                          {                                      case 1:                                                                          sortfloat();                                                 printhightolow();                                                 break;                                      case 2:                                                  sortfloat();                                                 printlowtohigh();                                                 break;                                      case 3:                                                 sortint();                                                 printhightolow();                                                 break;                                      case 4:                                                 sortint();                                                 printlowtohigh();                                                 break;                                      case 5:                                                  exit(0);                                                  break;                                      default:                                                  printf("Sorry! Entered a wrong value. Try again.");                          }              } while(1);              return 0;  }

Explanation / Answer

Possible problem with the code is that, you have put the & symbol at the print statements which is making the print statement to print the address of the variable. So to rectify the error you need to remove the & symbol in each print() statement. e.g.,

The above code must be replaced with the below rectified code.

And do the same in the remaining print() statements. Hope it will rectify the error, if not then you need to post the text file as well along with the codes in another question post.