Menu

[Solved]Need C Programming Pls Thank Project 7 Include Include Include Struct Supply Char Name 100 Q37026276

I need this in C programming pls. Thank you!

2. (30 points) Modify project 7 so that it uses qsort function to sort the array of supply instead of the selection sort func

******** Project 7 ********

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct supply
{   
char name[100];
char color[100];
int quantity;
};

// sort function prototype
void selection_sort(struct supply list[], int n);

int main(){

char file[100];
printf(“Enter the file name: “);
scanf(“%s”, file);

// file opened to read
FILE *inputFile = fopen(file, “r”);

// checking file status
if(inputFile == NULL)
{
printf(“Can’t open filen”);
return 1;
}

struct supply list[200];

// reading data
int i = 0;
while(1)
{
if(feof(inputFile))
{
break;
}
fscanf(inputFile, “%s %d %[^n]n”, list[i].color,&list[i].quantity, list[i].name);
i++;
}

selection_sort(list, i);

// file name changed
char outputName[107] = “sorted_”;

int j,k;

for(j = 7, k = 0; j < strlen(file)+7; j++, k++)
{
outputName[j] = file[k];
}

FILE *outputFile = fopen(outputName, “w”);

if(outputFile == NULL)
{
printf(“Cannot open output file!n”);
return 1;
}

// To sort data
for(j = 0; j < i; j++)
{
fprintf(outputFile, “%s       %d       %sn”, list[j].color,list[j].quantity, list[j].name);
}

// closing both files
fclose(inputFile);
fclose(outputFile);

return 0;
}

void selection_sort(struct supply list[], int n)
{
struct supply a;
int i, j, min;
for(i = 0; i < n-1; i++)
{
min = i;
for(j = i+1; j < n; j++)
{
int r = strcmp(list[j].name , list[min].name );
if(r < 0)
{
a = list[min];
list[min] = list[j];
list[j] = a;
}
}
}
}

2. (30 points) Modify project 7 so that it uses qsort function to sort the array of supply instead of the selection sort function. Your program should include a comparison function that compares struct supply for qsort function This program will be graded based on whether comparison function and gsort function call are implemented correctly Show transcribed image text 2. (30 points) Modify project 7 so that it uses qsort function to sort the array of supply instead of the selection sort function. Your program should include a comparison function that compares struct supply for qsort function This program will be graded based on whether comparison function and gsort function call are implemented correctly

Expert Answer


Answer to I need this in C programming pls. Thank you! ******** Project 7 ******** #include #include #include struct supply { char… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *