Question: C language Assignment: Create a program that prints a class roll sheet in alphabetical order. The user inputs the students' first name and last names

C language Assignment: "Create a program that prints a class roll sheet in alphabetical order. The user inputs the students' first name and last names (separately!), and presses enter on the first name when done. The program prints out the roster like this...

HATFIELD, HEIDI KAISER, RUSSELL LIPSHUTZ, HOWARD PENKERT, DAWN WRIGHT, ELIZABETH

Change limit[ ] to represent first name. The input should work for 30 students and first name should be 15 characters. Change prompts as needed. Compile and test. Make changes to convert the first name to all upper case using a function. Add another array and get input for last name which will also be an array of 30 with 15 characters. Combine last and first into an third array. "

Please debug my code below:

#include //header file for input/output

#include

#include

#define SIZE 81 /* string length limit, including \0 */

#define LIM 20 /* maximum number of lines to be read */

#define HALT "" /* null string to stop input */

void stsrt2(char *strings[], int num);/* string-sort function */

char * s_gets(char * st, int n);

void roll(void)

{

char input[LIM][SIZE]; /* array to store input */

char *ptstr[LIM]; /* array of pointer variables */

int ct = 0; /* input count */

int k; /* output count */

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]; /* set ptrs to strings */

ct++;

}

stsrt2(ptstr, ct); /* string sorter */

puts(" Here's the sorted list: ");

for (k = 0; k < ct; k++)

puts(ptstr[k]) ; /* sorted pointers */

}

/* string-pointer-sorting function */

void stsrt2(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 // must have words[i] == '\0'

while (getchar() != ' ')

continue;

}

return ret_val;

}

My code does not work. Please help me correct to meet the assignment requirement. Please do not forget to send me a screenshot of your program that it is working just to confirm it. Thanks in advance for your help.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!