Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the c program in the below to actually sort the array containing the strings. #include #include #define SIZE 81 #define LIM 20 #define HALT

 Modify the c program in the below to actually sort the array containing the strings. 

#include #include #define SIZE 81 #define LIM 20 #define HALT "" void stsrt(char *strings[], int num); char * s_gets(char * st, int n);

int main(void) { char input[LIM][SIZE]; char *ptstr[LIM]; int ct = 0; int k;

printf("Input up to %d lines, and I will sort them. ",LIM); printf("To stop, press the Enter key at a line's start. "); while (ct < LIM && s_gets(input[ct], SIZE) != NULL && input[ct][0] != '\0') { ptstr[ct] = input[ct]; ct++; } stsrt(ptstr, ct); puts(" Here's the sorted list: "); for (k = 0; k < ct; k++) puts(ptstr[k]) ;

return 0; }

void stsrt(char *strings[], int num) { char *temp; int top, seek;

for (top = 0; top < num-1; top++) for (seek = top + 1; seek < num; seek++) if (strcmp(strings[top],strings[seek]) > 0) { temp = strings[top]; strings[top] = strings[seek]; strings[seek] = temp; } }

char * s_gets(char * st, int n) { char * ret_val; int i = 0;

ret_val = fgets(st, n, stdin); if (ret_val) { while (st[i] != ' ' && st[i] != '\0') i++; if (st[i] == ' ') st[i] = '\0'; else while (getchar() != ' ') continue; } return ret_val; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

10-9 How have social technologies changed e-commerce?

Answered: 1 week ago